HDU_1398 Square Coins(生成函数)

  母函数模板题,就是稍微改了一下。

My Code:

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int N = 307;

int c1[N], c2[N];

int main() {
//freopen("data.in", "r", stdin);

int n, i, j, k;
while(cin >> n, n) {
for(i = 0; i <= n; i++) {
c1[i] = 1; c2[i] = 0;
}
for(i = 2; i <= n; i++) {
for(j = 0; j <= n; j++) {
for(k = 0; k + j <= n; k += i*i) { //因为硬币的序列是1*1, 2*2, 3*3 。。。17*17。。。
c2[k+j] += c1[j];
}
}
for(j = 0; j <= n; j++) {
c1[j] = c2[j]; c2[j] = 0;
}
}
printf("%d\n", c1[n]);
}
return 0;
}



原文地址:https://www.cnblogs.com/vongang/p/2261614.html