hdu 1398 整数划分变形 (母函数)
有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数
比如10
全1
4 + 6个 1
4+4+1+1
9+1
求(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^10)(1+x^4+x^8)(1+x^9)中
x^10的系数即可
只是把模板的 i<=n改成了i*i<=n,
在k遍历指数时把k=k+i变成了k=k+i*i
Sample Input
2
10
30
0
Sample Output
1
4
27
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 if (n == 0) 21 break ; 22 for(i=0; i<=n; ++i) 23 { 24 c1[i] = 1; 25 c2[i] = 0; 26 } 27 for(i=2; i*i<=n; ++i) 28 { 29 30 for(j=0; j<=n; ++j) 31 for(k=0; k+j<=n; k += i*i) 32 { 33 c2[j+k] += c1[j]; 34 } 35 for(j=0; j<=n; ++j) 36 { 37 c1[j] = c2[j]; 38 c2[j] = 0; 39 } 40 } 41 cout << c1[n] << endl; 42 } 43 return 0; 44 }