傻逼记忆化搜索 可是比赛时候我没去敲 赛后1A什么的还是退坑的好
Feed the monkey
Time Limit: 2000MS Memory limit: 131072K
题目描述
Alice has a monkey, she must feed fruit to the monkey every day.She has three kinds of fruits, bananas,
peaches and apples. Every day, she chooses one in three, and pick one of this to feed the monkey.
But the monkey is picky, it doesn’t want bananas for more than D1 consecutive days, peaches for more than D2
consecutive days, or apples for more than D3 consecutive days. Now Alice has N1 bananas, N2 peaches and N3
apples, please help her calculate the number of schemes to feed the monkey.
输入
Multiple test cases. The first line contains an integer T (T<=20), indicating the number of test case.
Each test case is a line containing 6 integers N1, N2, N3, D1, D2, D3 (N1, N2, N3, D1, D2, D3<=50).
输出
One line per case. The number of schemes to feed the monkey during (N1+N2+N3) days.
The answer is too large so you should mod 1000000007.
示例输入
1 2 1 1 1 1 1
示例输出
6
提示
Answers are BPBA, BPAB, BABP, BAPB, PBAB, and ABPB(B-banana P-peach A-apple)
来源
示例程序
ACcode:#include <bits/stdc++.h>
#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#define maxn 52
#define mod 1000000007
using namespace std;
int dp[maxn][maxn][maxn][3][maxn];
int A,B,C,a,b,c,sum;
inline int dfs(int x,int y,int z,int t,int n){
if(x>A||y>B||z>C||x+y+z>sum)return 0;
if(t==0&&n>a||t==1&&n>b||t==2&&n>c)return 0;
if(dp[x][y][z][t][n]!=-1)return dp[x][y][z][t][n];
if(x+y+z==sum)return 1;
int ans=0;
if(t==0){
ans=(ans+dfs(x+1,y,z,0,n+1))%mod;
ans=(ans+dfs(x,y+1,z,1,1))%mod;
ans=(ans+dfs(x,y,z+1,2,1))%mod;
return dp[x][y][z][t][n]=ans;
}
if(t==1){
ans=(ans+dfs(x+1,y,z,0,1))%mod;
ans=(ans+dfs(x,y+1,z,1,n+1))%mod;
ans=(ans+dfs(x,y,z+1,2,1))%mod;
return dp[x][y][z][t][n]=ans;
}
if(t==2){
ans=(ans+dfs(x+1,y,z,0,1))%mod;
ans=(ans+dfs(x,y+1,z,1,1))%mod;
ans=(ans+dfs(x,y,z+1,2,n+1))%mod;
return dp[x][y][z][t][n]=ans;
}
}
int main(){
int loop;
scanf("%d",&loop);
for(;loop--;){
scanf("%d%d%d%d%d%d",&A,&B,&C,&a,&b,&c);
sum=A+B+C;
memset(dp,-1,sizeof(dp));
int ans=0;
ans=(ans+dfs(1,0,0,0,1))%mod;
ans=(ans+dfs(0,1,0,1,1))%mod;
ans=(ans+dfs(0,0,1,2,1))%mod;
printf("%d\n",ans);
}
return 0;
}