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 cnt[21][21][21]; //保存信息 int w(int a,int b,int c) { if(a<=0||b<=0||c<=0) return 1; if(cnt[a][b][c]>0) return cnt[a][b][c]; 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 a,b,c; while(cin>>a>>b>>c) { memset(cnt,0,sizeof(cnt)); if(a==-1&&b==-1&&c==-1) break; for(int i=1;i<=20;i++) for(int j=1;j<=20;j++) for(int k=1;k<=20;k++) cnt[i][j][k]=w(i,j,k); if(a<=0||b<=0||c<=0) cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<1<<endl; else if(a>20||b>20||c>20) cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<cnt[20][20][20]<<endl; else cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<cnt[a][b][c]<<endl; } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator