您的位置:首页 > Web前端

第7届山东省赛----sdut 3565 Feed the monkey

2016-10-10 20:02 246 查看


Problem Description

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.


Input

 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).


Output

 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.


Example Input

1
2 1 1 1 1 1



Example Output

6



Hint

 Answers are BPBA, BPAB, BABP, BAPB, PBAB, and ABPB(B-banana P-peach A-apple)


Author

 “浪潮杯”山东省第七届ACM大学生程序设计竞赛

省赛的题,状态转移dp,自己太菜没做出来

dp[a][b][c][t][e],a,b,c表示剩余的3种水果的数量,t表示前一天选择的哪一种水果,e表示前一天选择的水果已被连续选择的天数

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll dp[55][55][55][5][55];
int n1,n2,n3,d1,d2,d3;
ll dfs(int a,int b,int c,int t,int e)
{
if(a<0||b<0||c<0)
return 0;
if(t==0&&e>d1||t==1&&e>d2||t==2&&e>d3)
return 0;
if(a==0&&b==0&&c==0)
return 1;
if(dp[a][b][c][t][e]!=-1)
return dp[a][b][c][t][e];
ll ans=0;
if(t==0)
{
ans=(ans+dfs(a-1,b,c,0,e+1))%mod;
ans=(ans+dfs(a,b-1,c,1,1))%mod;
ans=(ans+dfs(a,b,c-1,2,1))%mod;
return dp[a][b][c][t][e]=ans;
}
if(t==1)
{
ans=(ans+dfs(a-1,b,c,0,1))%mod;
ans=(ans+dfs(a,b-1,c,1,e+1))%mod;
ans=(ans+dfs(a,b,c-1,2,1))%mod;
return dp[a][b][c][t][e]=ans;
}
if(t==2)
{
ans=(ans+dfs(a-1,b,c,0,1))%mod;
ans=(ans+dfs(a,b-1,c,1,1))%mod;
ans=(ans+dfs(a,b,c-1,2,e+1))%mod;
return dp[a][b][c][t][e]=ans;
}

}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d%d%d%d%d",&n1,&n2,&n3,&d1,&d2,&d3);
memset(dp,-1,sizeof(dp));
ll ans=0;
ans=(ans+dfs(n1-1,n2,n3,0,1))%mod;
ans=(ans+dfs(n1,n2-1,n3,1,1))%mod;
ans=(ans+dfs(n1,n2,n3-1,2,1))%mod;
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: