POJ1579(Function Run Fun)

题目链接

简单的动态规划题,WA了4次居然是因为N太小,为自己的吝啬感到无语。

View Code
 1 #include <stdio.h>
2 #define N 21
3 int f[N][N][N];
4 int w(int a,int b,int c)
5 {
6 if(a<=0 || b<=0 || c<=0) return 1;
7 if(a>20 || b>20 || c>20) return w(20,20,20);
8 if(f[a][b][c]>0) return f[a][b][c];
9 if(a<b&&b<c) return f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
10 else return f[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);
11 }
12 int main()
13 {
14 int a,b,c;
15 while(scanf("%d%d%d",&a,&b,&c)!=EOF)
16 {
17 if(a==-1&&b==-1&&c==-1) break;
18 memset(f,-1,sizeof(f));
19 printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c));
20 }
21 return 0;
22 }


 

posted @ 2012-04-06 17:02  BeatLJ  阅读(213)  评论(0编辑  收藏  举报