Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单的DP吧,用个3维数组记住信息就行了#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <functional> #include <list> #include <map> #include <set> using namespace std; int w[30][30][30]; int a,b,c; class POJ { public: int POJMethod() { int i,j,k; for(i = 0;i<=20;++i) for(j = 0;j<=20;++j) for(k = 0;k<=20;++k) { if(i==0 || j==0 || k==0) {w[i][j][k] = 1; } else 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]; } if(a<=0||b<=0||c<=0) return w[0][0][0]; if(a>=20||b>=20||c>=20) return w[20][20][20]; return w[a][b][c]; } }; int main() { while((cin>>a>>b>>c) && (a!=-1||b!=-1||c!=-1)) { POJ test; printf("w(%d, %d, %d) = %d\n",a,b,c,test.POJMethod()); } system("pause"); return 0; }; Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator