Kaidul

Cricinfo

Nov 15th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. #define Mod 10000007
  8. #define M 10
  9. #define Max 10001
  10.  
  11. int runs[] = {0, 1, 2, 3, 4, 6, 1, 2, 3, 5, 1, 2, 5, 7, 0};
  12. int N, n, depth, ans, extra[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0};
  13. int dp[M][Max];
  14.  
  15. int solve(int indx, int sum) {
  16.     if(indx == depth)
  17.         return 1;
  18.     if(sum <= 0)
  19.         return 1;
  20.  
  21.     if(dp[indx][sum] != -1)
  22.         return dp[indx][sum];
  23.  
  24.     int ans = 0;
  25.     for (int i = 0; i < n; i++)
  26.         ans = (ans % Mod + solve(indx + 1 - extra[i], sum - runs[i]) % Mod) % Mod;
  27.  
  28.     return dp[indx][sum] = (ans + 1) %  Mod;
  29. }
  30.  
  31.  
  32. int main() {
  33.     depth = 6, n = sizeof(runs) / sizeof(runs[0]);
  34.     int tcase, caseNo = 0;
  35.     scanf("%d", &tcase);
  36.     memset(dp, -1, sizeof dp);
  37.     while (tcase--) {
  38.         scanf("%d", &N);
  39.         printf("Case %d: %d\n", ++caseNo, solve(0, N));
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment