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 |
wa#include<stdio.h> int w[21][21][21],i,j,k; int ww(int a,int b,int c) { if(w[a][b][c]!=-1) return w[a][b][c]; for(i=0;i<=20;i++) for(j=0;j<=20;j++) for(k=0;k<=20;k++) if(i<j&&j<k) w[i][j][k]=ww(i,j,k-1)+ww(i,j-1,k-1)-ww(i,j-1,k); else w[i][j][k]=ww(i-1,j,k)+ww(i-1,j-1,k)+ww(i-1,j,k-1)-ww(i-1,j-1,-1); return w[a][b][c]; } int main() { for(i=0;i<=20;i++) for(j=0;j<=20;j++) for(k=0;k<=20;k++) w[i][j][k]=-1; for(i=0;i<=20;i++) for(j=0;j<=20;j++) { w[0][i][j]=1; w[i][0][j]=1; w[i][j][0]=1; } while(scanf("%d%d%d",&i,&j,&k)&&i!=-1) { printf("w(%d, %d, %d) = ",i,j,k); if(i<0||i==0||j<0||j==0||k<0||k==0) printf("1\n"); else if(i>20||j>20||k>20) printf("%d\n",ww(20,20,20)); else printf("%d\n",ww(i,j,k)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator