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 |
Re:一道真正自己做的dp加递归!!!!In Reply To:一道真正自己做的dp加递归!!!! Posted by:wangbaobao at 2009-05-11 19:46:51 #include<iostream> using namespace std; int tt[21][21][21]; int w(int a,int b,int c) { if(a<=0 || b<=0 || c<=0)return 1; else if(tt[a][b][c])return tt[a][b][c]; else if(a<b && b<c) return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); else return 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 i,j,k,a,b,c,d; for(i=1;i<21;i++) for(j=1;j<21;j++) for(k=1;k<21;k++) tt[i][j][k]=w(i,j,k); while(scanf("%d%d%d",&a,&b,&c) && !(a==-1 && b==-1 && c==-1)) { if(a<=0 || b<=0 || c<=0)d=1; else if(a>20 || b>20 || c>20){d=w(20,20,20);} else d=tt[a][b][c]; printf("w(%d, %d, %d) = %d\n",a,b,c,d); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator