... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Tuesday, December 31, 2013

LOJ-1006 :: Hex-a-bonacci

#include <iostream>
#include <bits/stdc++.h>
using namespace std ;

 long long int dp[10002] ,vis[10002] ;
int a, b, c, d, e, f ,i ;

long long int fn( int n )
{
    if( n == 0 ) return a;
    if( n == 1 ) return b;
    if( n == 2 )  return c;
    if( n == 3 ) return d;
    if( n == 4 ) return e;
    if( n == 5 ) return f;

    if (vis[n] != -1) return dp[n] ;
    else vis[n]=1 ;

     return dp[n]=( ( (fn(n-1) % 10000007) + (fn(n-2)%10000007) + (fn(n-3)%10000007) + (fn(n-4)%10000007)+(fn(n-5)%10000007)+(fn(n-6)%10000007) )%10000007 ) ;
   }

int main()
 {
    int n, caseno = 0, cases;
    scanf("%d", &cases);

    while( cases-- )
        {
                 memset (vis,-1,sizeof (vis)) ;

        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        printf("Case %d: %lld\n", ++caseno,   fn(n)% 10000007);
    }
    return 0;
}