hdu 1028 整数划分 (母函数)

假如输入4
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
一共5种

假如输入3 用母函数的方法就是写成
(1+X+X2+X3)(1+X2)(1+X3) 展开后 求X3的系数

假如输入n
就是(1+X+X2+X3+X4....)(1+X2+X4+X6..)(1+X3+X6...)(....)

Sample Input
4
10
20

Sample Output
5
42
627

 

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <string>
 6 # include <cmath>
 7 # include <queue>
 8 # include <list>
 9 # define LL long long
10 using namespace std ;
11 
12 int c1[10010], c2[10010] ;
13 int main()
14 {
15     //freopen("in.txt","r",stdin) ;
16     int n;
17     int i, j, k;
18     while(cin >> n)
19     {
20         for(i=0; i<=n; ++i)
21         {
22             c1[i] = 1;
23             c2[i] = 0;
24         }
25         for(i=2; i<=n; ++i)
26         {
27 
28             for(j=0; j<=1*n; ++j)
29                 for(k=0; k <= 2*n; k += i)
30                 {
31                     c2[j+k] += c1[j];
32                 }
33                 for(j=0; j<=n; ++j)
34                 {
35                     c1[j] = c2[j];
36                     c2[j] = 0;
37                 }
38         }
39         cout << c1[n] << endl;
40     }
41     return 0;
42 }
View Code

 

posted @ 2015-09-22 21:46  __Meng  阅读(250)  评论(0编辑  收藏  举报