lihgtoj 1006

时间:2023-03-08 16:47:02
lihgtoj 1006

记忆化搜索下即可。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
const int MAXN = 10010;
const int MOD = 10000007;
using namespace std;
long long int dp[MAXN];
int a, b, c, d, e, f;
int fn( int n ) {
//if(n < 0) return 0;
if(dp[n] != -1) return dp[n] % MOD;
dp[n] = (fn(n-1) % MOD + fn(n-2) % MOD + fn(n-3) % MOD + fn(n-4) % MOD + fn(n-5) % MOD + fn(n-6) % MOD) % MOD;
return dp[n] % MOD;
}
int main() {
int n, caseno = 0, cases;
scanf("%d", &cases);
while( cases-- ) {
memset(dp, -1, sizeof dp);
for(int i = 0;i < 6;i ++) {
cin >> dp[i];
}
scanf("%d", &n);
printf("Case %d: %lld\n", ++caseno, fn(n));
}
return 0;
}