hdu1028 另一个参考答案
1
2
3
4
5
6
7
8
9 #include
10 #define N 8000
11
12 using namespace std;
13 int n;
14 int a[N],b[N],ab[N];
15
16 int Num()
17 {
18 int i,j,k;
19
20 memset(ab, 0 ,sizeof(ab));
21 for(i = 0; i <= n ; i++)
22 ab[i] = 1;
23
24 for(k = 2; k <= n; k++)
25 {
26
27 memcpy(b, ab, sizeof(ab));
28
29 for(i = 0; i <= n; i++)
30 {
31 a[i] = 0;
32 ab[i] = 0;
33 }
34
35
36 for(i = 0; i <= n; i += k)
37 a[i] = 1;
38
39 for(i = 0; i <= n; i++)
40 for(j = 0; j <= n; j++)
41 {
42 ab[i+j] += a[i]*b[j];
43 if(i + j > n)
44 break;
45 }
46 }
47 return ab[n];
48 }
49
50 int main()
51 {
52 int res;
53 while(scanf("%d",&n) != EOF)
54 {
55 res = Num();
56 printf("%d\n",res);
57 }
58 return 0;
59 }
hdu1028 另一个参考答案 (2008-10-11 17:37:14由218编辑)