HDU - 1028 Ignatius and the Princess III 生成函数
可见,可以求出0-10克的重量,且方案数都是1.
此题就是用多项式相乘的原理求幂次和系数。
int c1[130]; int c2[130]; int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i <= n; i++) c1[i] = 1, c2[i] = 0; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n; j++) for (int k = 0; k + j <= n; k += i) c2[k + j] += c1[j]; for (int j = 0; j <= n; j++) { c1[j] = c2[j]; c2[j] = 0; } } printf("%d\n", c1[n]); } }