Feed the monkey
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.
Sample Input
1 2 1 1 1 1 1
Sample Output
6
Hint
Answers are BPBA, BPAB, BABP, BAPB, PBAB, and ABPB(B-banana P-peach A-apple)
Source
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=200;
ll dp[N][N][N][3];
int n1,n2,n3,d1,d2,d3;
int main()
{
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>n1>>n2>>n3>>d1>>d2>>d3;
memset(dp,0,sizeof(dp));
for(int i=n1;i>=0;i--)
for(int j=n2;j>=0;j--)
for(int k=n3;k>=0;k--){
for(int s=1;s<=min(d1,i);s++){
if(i==n1&&j==n2&&k==n3){
dp[i-s][j][k][0]=1;
}else{
dp[i-s][j][k][0]=((dp[i-s][j][k][0]+dp[i][j][k][1])%mod+dp[i][j][k][2])%mod;
}
}
for(int s=1;s<=min(d2,j);s++){
if(i==n1&&j==n2&&k==n3){
dp[i][j-s][k][1]=1;
}else{
dp[i][j-s][k][1]=((dp[i][j-s][k][1]+dp[i][j][k][0])%mod+dp[i][j][k][2])%mod;
}
}
for(int s=1;s<=min(d3,k);s++){
if(i==n1&&j==n2&&k==n3){
dp[i][j][k-s][2]=1;
}else{
dp[i][j][k-s][2]=((dp[i][j][k-s][2]+dp[i][j][k][1])%mod+dp[i][j][k][0])%mod;
}
}
}
ll ans=((dp[0][0][0][0]+dp[0][0][0][1])%mod+dp[0][0][0][2])%mod;
cout<<ans<<endl;
}
return 0;
}