POJ 1579 解法一常规解法利用数组来解答,较容易想。

 1 #include<stdio.h>
2 int w[21][21][21];
3 int main()
4 {
5 int a,b,c;
6
7 for(a=0; a<21; a++)
8 for(b=0; b<21; b++)
9 for(c=0; c<21; c++)
10 {
11 if(a<=0||b<=0||c<=0)
12 w[a][b][c] = 1;
13 else if(a<b && b<c)
14 w[a][b][c] = w[a][b][c-1]+w[a][b-1][c-1]-w[a][b-1][c];
15 else
16 w[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];
17 }
18 while(1)
19 {
20 scanf("%d%d%d", &a, &b, &c);
21 if(a==-1 && b==-1 && c==-1) break;
22 printf("w(%d, %d, %d) = ",a,b,c);
23 if(a<=0 || b<=0 || c<=0)
24 {
25 a = 0;
26 b = 0;
27 c = 0;
28 }
29 else if(a>20 || b>20 || c>20)
30 {
31 a = 20;
32 b = 20;
33 c = 20;
34 }
35
36 printf("%d\n",w[a][b][c]);
37 }
38 return 0;
39 }
40

  

posted @ 2011-08-21 21:40  zhongya  阅读(127)  评论(0编辑  收藏  举报