山东省第七届 ACM 省赛 Feed the monkey (dp)
来源:互联网 发布:linux下创建用户 编辑:程序博客网 时间:2024/06/16 07:34
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
12 1 1 1 1 1
Example Output
6
题意
给出三种水果以及每种水果不能连续的数量,求总共有多少种组合的方式。
思路
dp[a][b][c][k]
代表当前剩余第一种水果 a
个,剩余第二种水果 b
个,剩余第三种水果 c
个,并且以 k
结尾所有的组合数。
枚举所有的 a,b,c
, dp[s][b][c][0]
可以由 dp[a][b][c][1]
与 dp[a][b][c][2]
转移而来,其中 s
为保证第一种水果最多连续不超过 d[0]
的水果数目。
因此 s
取值范围为: [max(0,a-d[0]),a)
。
第二种水果和第三种水果的转移也类似,输出 mod 1e9+7
之后的结果。
AC 代码
#include<bits/stdc++.h>using namespace std;const int mod = 1000000007;typedef long long LL;LL dp[51][51][51][3];int n[3],d[3];int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--) { memset(dp,0,sizeof(dp)); for(int i=0; i<3; i++) cin>>n[i]; for(int i=0; i<3; i++) cin>>d[i]; for(int a=n[0]; a>=0; a--) { for(int b=n[1]; b>=0; b--) { for(int c=n[2]; c>=0; c--) { for(int s=max(0,a-d[0]); s<a; s++) { if(a==n[0]&&b==n[1]&&c==n[2]) dp[s][b][c][0]=(dp[s][b][c][0]+1)%mod; else dp[s][b][c][0]=(dp[s][b][c][0]+dp[a][b][c][1]+dp[a][b][c][2])%mod; } for(int s=max(0,b-d[1]); s<b; s++) { if(a==n[0]&&b==n[1]&&c==n[2]) dp[a][s][c][1]=(dp[a][s][c][1]+1)%mod; else dp[a][s][c][1]=(dp[a][s][c][1]+dp[a][b][c][0]+dp[a][b][c][2])%mod; } for(int s=max(0,c-d[2]); s<c; s++) { if(a==n[0]&&b==n[1]&&c==n[2]) dp[a][b][s][2]=(dp[a][b][s][2]+1)%mod; else dp[a][b][s][2]=(dp[a][b][s][2]+dp[a][b][c][0]+dp[a][b][c][1])%mod; } } } } cout<<((dp[0][0][0][0]+dp[0][0][0][1])%mod+dp[0][0][0][2])%mod<<endl; } return 0;}
- 山东省第七届 ACM 省赛 Feed the monkey (dp)
- 山东省第七届ACM省赛 Feed the monkey
- 第七届 山东省ACM Feed the monkey(记忆化搜索 OR DP )
- 第七届ACM山东省赛-F Feed the monkey
- 山东省第七届ACM F Feed the monkey (记忆搜索)
- 第七届山东省赛 Feed the monkey(dp)
- 山东省第7届ACM省赛 F题 Feed the monkey dp
- 第7届山东省赛----sdut 3565 Feed the monkey
- SDUT 3565 Feed the monkey(DP)
- 山东省第七届ACM省赛------The Binding of Isaac
- 第七届山东省ACM省赛 E The Binding of Isaac
- 山东省第七届 ACM 省赛 Proxy (最短路)
- 山东省第七届ACM省赛------Julyed
- 山东省第七届ACM省赛------Fibonacci
- 山东省第七届ACM省赛------Triple Nim
- 山东省第七届ACM省赛------Reversed Words
- 山东省第七届ACM省赛------Memory Leak
- 山东省第七届ACM省赛 Triple Nim
- HDU 1166 敌兵布阵(树状数组)
- 平衡二叉树的插入C语言
- 欢迎使用CSDN-markdown编辑器
- Longest Absolute File Path
- 《Android那些事》——Android框架分析
- 山东省第七届 ACM 省赛 Feed the monkey (dp)
- #1141 : 二分·归并排序之逆序对
- pat 甲级 1126. Eulerian Path java实现
- PHP GPG 加密实践
- Laravel 发送邮件(smtp方式最简单的讲解!)-邮件部分
- Android开发中的一些问题小计1(读写数据)
- cuda shared(共享内存)—一个容易错误的点
- 程序编译链接感触
- iOS上传App Store报错:this action cannot be completed -22421 解决方案