pku 1579

#include <iostream> using namespace std; int w[21][21][21]; /* int wg(int a, int b, int c) { if(a <= 0 || b <=0 || c<=0) return 1; else if(a> 20 || b > 20 || c > 20) return wg(20, 20, 20); else if(a < b && b < c) return wg(a, b, c-1) + wg(a, b-1, c-1) - wg(a, b-1, c); else return wg(a-1, b, c) + wg(a-1, b-1, c) + wg(a-1, b, c-1) - wg(a-1, b-1, c-1); }*/ //简单动态规划,思想: // 预先利用迭代做好表格. int main() { int a, b, c; //initialize for(int i = 0; i <= 20; ++i) for(int j = 0; j <= 20; ++j) w[i][j][0] = 1; for(int i = 0; i <= 20; ++i) for(int j = 0; j <= 20; ++j) w[0][i][j] = 1; for(int i = 0; i <= 20; ++i) for(int j = 0; j <= 20; ++j) w[i][0][j] = 1; //dp for(int i = 1; i <= 20; ++i) for(int j = 1; j <= 20; ++j) for(int k = 1; k <= 20; ++k) if(i < j && j < k) w[i][j][k] = w[i][j][k-1] + w[i][j-1][k-1] - w[i][j-1][k]; else w[i][j][k] = w[i-1][j][k] + w[i-1][j-1][k] + w[i-1][j][k-1] - w[i-1][j-1][k-1]; while(scanf("%d%d%d", &a, &b, &c) && !(a==-1 && b==-1 && c==-1)) { if(a <= 0 || b <=0 || c<=0) printf("w(%d, %d, %d) = %d/n",a, b, c, 1); else if(a > 20 || b > 20 || c > 20) printf("w(%d, %d, %d) = %d/n",a, b, c,w[20][20][20]); else printf("w(%d, %d, %d) = %d/n",a, b, c,w[a][b][c]); } return 0; }  

你可能感兴趣的:(c,include)