这种母函数的见多了,也就简单了,不外乎就是一个多项式展开,我怎么恍惚中觉得我发过一篇类似的博客的,但是再回头去找的时候就没啦!
算了,下次再说吧。赶紧抢饭去咯!
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1284
参考代码:
#include <stdio.h> #define M 32768 void main() { int c1[M + 5]; int c2[M + 5]; int n; int i,j,k; for(i = 0; i <= M; ++i) { c1[i] = 1; c2[i] = 0; } for(i = 2; i <= 3; ++i) { for(j = 0; j <= M; ++j) { for(k = 0; k + j <= M; k += i) { c2[k + j] += c1[j]; } } for(j = 0; j <= M; ++j) { c1[j] = c2[j]; c2[j] = 0; } } while(scanf("%d",&n) != EOF) { if(n < 0) { continue; } if(n == 0) { printf("%d\n",n); continue; } printf("%d\n",c1[n]); } }
另外一个类似的题:http://acm.hdu.edu.cn/showproblem.php?pid=1398
#include <stdio.h> #define M 300 void main() { int c1[M+5]; int c2[M+5]; int n; int i,j,k; int temp; while(scanf("%d",&n)) { if(n == 0) { break; } for(i = 0; i <= M; ++i) { c1[i] = 1; c2[i] = 0; } //第一层循环表示(1+x^i)*...*(1+x^(ki))相关的因子 for(i = 2; i <= n; ++i) { temp = i * i; for(j = 0; j <= n; ++j)//第二层循环遍历已有的因子的系数 { for(k = 0; k + j <= n; k += temp) { c2[k + j] += c1[j]; } } for(j = 0; j <=n; ++j) { c1[j] = c2[j]; c2[j] = 0; } } printf("%d\n",c1[n]); } }