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,贴代码水过~~~#include <iostream> using namespace std; int cw[22][22][22]; int w(int a,int b,int c) { if(a <= 0 || b <= 0 || c <= 0) return 1; else if(a > 20 || b > 20 || c > 20) return w(20,20,20); else if(cw[a][b][c] > 0) return cw[a][b][c]; else if(a < b && b < c) return cw[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c) ; else return cw[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1) ; } int main() { int a,b,c; while(scanf("%d%d%d",&a,&b,&c) != EOF) { if(a == -1 && b == -1 && c == -1) break; memset(cw,-1,sizeof(cw)); printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator