Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13471 | Accepted: 7014 |
Description
Input
Output
Sample Input
1 1 1 2 2 2 10 4 6 50 50 50 -1 7 18 -1 -1 -1
Sample Output
w(1, 1, 1) = 2 w(2, 2, 2) = 4 w(10, 4, 6) = 523 w(50, 50, 50) = 1048576 w(-1, 7, 18) = 1
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int w[25][25][25]; int DFS(int a,int b,int c) { if(a<=0 || b<=0 || c<=0) { return 1; } if(a>20 || b>20 || c>20) { return DFS(20,20,20); } if(w[a][b][c]!=-1) { return w[a][b][c]; } if(a<b && b<c) { w[a][b][c] = DFS(a, b, c-1) + DFS(a, b-1, c-1) - DFS(a, b-1, c); } else { w[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); } return w[a][b][c]; } int main() { freopen("in.txt","r",stdin); int i,j,k; memset(w,-1,sizeof(w)); while(cin>>i>>j>>k) { if(i==-1&&j==-1&&k==-1) break; printf("w(%d, %d, %d) = %d\n",i,j,k,DFS(i,j,k)); } }