LETTers比赛第七场 奥数的烦恼
状态为DP[x][y][z]=DP[x-1][y][z-1]+DP[x][y-1][z]+DP[x][y][z-1];注意一点数值为长整型!
#include<stdio.h> #include<string.h> const int maxn=20; __int64 f[maxn][maxn][maxn]; int vis[maxn][maxn][maxn]; __int64 Solve(int a,int b,int c) { if(a<0||b<0||c<0)return 0; if(vis[a][b][c])return f[a][b][c]; vis[a][b][c]=1; __int64 &ans=f[a][b][c]; ans=Solve(a-1,b,c)+Solve(a,b-1,c)+Solve(a,b,c-1); return ans; } int main() { // freopen("testin","r",stdin); // freopen("testout1","w",stdout); int tt; scanf("%d",&tt); f[1][0][0]=1; f[0][1][0]=1; f[0][0][1]=1; //f[0][0][0]=0; while(tt--) { int a,b,c; scanf("%d%d%d",&a,&b,&c); memset(vis,0,sizeof(vis)); vis[1][0][0]=1;vis[0][1][0]=1;vis[0][0][1]=1; vis[0][0][0]=1; printf("%I64d\n",Solve(a,b,c)); } return 0; }