- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 10003
- #define md 10000007
- using namespace std;
- typedef long long LL;
- int a, b, c, d, e, f;
- int dp[S];
- 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(dp[n] != -1)return dp[n];
- dp[n] = ( fn(n-1)%md + fn(n-2)%md + fn(n-3)%md + fn(n-4)%md + fn(n-5)%md + fn(n-6)%md )%md;
- return dp[n]%md;
- }
- int main() {
- int n, caseno = 0, cases;
- scanf("%d", &cases);
- while( cases-- ) {
- memset(dp, -1, sizeof(dp));
- scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
- printf("Case %d: %d\n", ++caseno, fn(n) % md);
- }
- return 0;
- }
Saturday, June 6, 2015
LightOJ - 1006 - Hex-a-bonacci
Subscribe to:
Post Comments (Atom)
dp array size should be at least 1e5 otherwise the code will not wrok if n>6
ReplyDelete