Link
Meaning
Give you the number of 3 kinds of fruit, and the maximum number of consecutive days to eat fruit. Ask you how many kinds of programs monkeys eat fruit.
Point:
Memory search, at the beginning (pre=-1) can eat 3 kinds of fruit, and then change to eat search is good.
0 0 0 is definitely 1.
Found only a kind of fruit, it is necessary to see if you can eat it all at once. Because the remaining fruit can be greater than the maximum number of consecutive days.
DP initialization cannot be 0, can be 1, and then pruned. Because the answer to 0 is quite a lot. So-1 is better, no timeout.
I opened the VIS array separately.
#include <iostream> #include <stdio.h> #include <queue> #include <vector> #include <string.h
> #include <algorithm> using namespace std;
#define LL Long, const LL mod=1000000007;
LL Dp[55][55][55][4];
LL d1,d2,d3;
int vis[55][55][55][4];
ll Dfs (ll x,ll y,ll z,ll Pre) {ll num=0;
LL k=0;
if (x!=0) k=1,num++;
if (y!=0) k=2,num++;
if (z!=0) k=3,num++;
if (num==0) return 1;
if (num==1) {if (K==1&&X<=D1) return 1;
if (K==2&&Y<=D2) return 1;
if (K==3&&Z<=D3) return 1;
return 0;
} if (Pre!=-1&&vis[x][y][z][pre]) return dp[x][y][z][pre];
LL xx=min (X,D1);
LL yy=min (Y,D2);
LL zz=min (Z,D3);
LL ans=0;
if (pre==-1) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod; for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
} if (Pre==1) {for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod;
for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
} if (pre==2) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
} if (pre==3) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod;
} if (pre!=-1) dp[x][y][z][pre]=ans,vis[x][y][z][pre]=1;
return ans;
int main () {LL T;
scanf ("%lld", &t);
while (t--) {LL n1,n2,n3;
scanf ("%lld%lld%lld%lld%lld%lld", &n1,&n2,&n3,&d1,&d2,&d3);
for (int i=0;i<=n1;i++) for (int j=0;j<=n2;j++) for (int k=0;k<=n3;k++) For (inT t=0;t<=3;t++) vis[i][j][k][t]=0;
Cout<<dfs (n1,n2,n3,-1) <<endl;
return 0; }