第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;
}
相关文章推荐
- SDUT 3565 Feed the monkey(DP)
- sdut 3565 Feed the monkey dp
- 山东省第7届ACM省赛 F题 Feed the monkey dp
- SDUT 3565 Feed the monkey && sdut 2879 Colorful Cupcakes (dp)
- sdut3565——Feed the monkey(记忆化DP)
- SDUT 3565 Feed the monkey【Dp】
- 第七届 山东省ACM Feed the monkey(记忆化搜索 OR DP )
- 第七届ACM山东省赛-F Feed the monkey
- 山东省第七届ACM F Feed the monkey (记忆搜索)
- 山东省第七届 ACM 省赛 Feed the monkey (dp)
- 第七届山东省赛 Feed the monkey(dp)
- 山东省第七届ACM省赛 Feed the monkey
- sdut oj 3665 Feed the monkey(dp)
- 山东省第7届省赛 E题 The Binding of Isaac
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- sdut 2603 Rescue The Princess(算是解析几何吧)(山东省第四届ACM省赛A题)
- 第7届山东省赛sdut 3566---Triple Nim
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- 山东省第四届ACM省赛 A SDUT 2603 Rescue The Princess(简单数学题)
- SDUTRescue The Princess(数学问题)