http://acm.hdu.edu.cn/showproblem.php?pid=1331
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int dp[30][30][30]; 7 8 int dfs(int a,int b,int c) 9 { 10 if(a<=0||b<=0||c<=0) return 1; 11 if(dp[a][b][c]!=0) return dp[a][b][c]; 12 if(a<b&&b<c) 13 { 14 return dp[a][b][c]=dfs(a,b,c-1)+dfs(a,b-1,c-1)-dfs(a,b-1,c); 15 } 16 else 17 return dp[a][b][c]=dfs(a-1,b,c)+dfs(a-1,b-1,c)+dfs(a-1,b,c-1)-dfs(a-1,b-1,c-1); 18 } 19 20 int main() 21 { 22 int a,b,c; 23 while(scanf("%d%d%d",&a,&b,&c)!=EOF) 24 { 25 if(a==-1&&b==-1&&c==-1) break; 26 if(a<=0||b<=0||c<=0) 27 { 28 printf("w(%d, %d, %d) = %d ",a,b,c,1); 29 } 30 else if(a>20||b>20||c>20) 31 { 32 printf("w(%d, %d, %d) = %d ",a,b,c,dfs(20,20,20)); 33 } 34 else 35 printf("w(%d, %d, %d) = %d ",a,b,c,dfs(a,b,c)); 36 } 37 return 0; 38 }