SHARE
TWEET

lightoj 1006 mmm

a guest Jul 17th, 2013 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstdio>
  3.  
  4. using namespace std;
  5.  
  6. long  a, b, c, d, e, f;
  7. unsigned long long ans[10010];
  8. unsigned long long fn( int n ) {
  9.     if( n == 0 ) return a;
  10.     else if( n == 1 ) return b;
  11.     else if( n == 2 ) return c;
  12.     else if( n == 3 ) return d;
  13.     else if( n == 4 ) return e;
  14.     else if( n == 5 ) return f;
  15.     else if(ans[n]==-1) ans[n]=( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
  16.  
  17.     return ans[n];
  18. }
  19. int main() {
  20.     int n, caseno = 0, cases;
  21.     scanf("%ld", &cases);
  22.     while( cases-- ) {
  23.         for(int i=0;i<10010;i++)
  24.             ans[i]=-1;
  25.         scanf("%ld %ld %ld %ld %ld %ld %d", &a, &b, &c, &d, &e, &f, &n);
  26.         unsigned long long i=fn(n);
  27.         //cout<<fn(n)%10000007<<endl;
  28.         i=i % 10000007;
  29.  
  30.         printf("Case %d: %llu\n", ++caseno,i);
  31.     }
  32.     return 0;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top