分析:母函数(详细见找单词)
代码:
#include<cstdio>
#include<cstring>
const int maxn = 1000;
int c1[maxn], c2[maxn], a[20];
int main(){
int n;
for(int i = 1; i < 18; i++)
a[i] = i*i;
while(scanf("%d", &n), n){
memset(c1, 0, sizeof(c1));
c1[0] = 1;
memset(c2, 0, sizeof(c2));
for(int i = 1; i < 18; i++){
for(int j = 0; j*a[i] <= n; j++)
for(int k = j*a[i]; k <= n; k++)
c2[k] += c1[k - j*a[i]];
memcpy(c1, c2, sizeof(c2));
memset(c2, 0, sizeof(c2));
}
printf("%d\n", c1[n]);
}
return 0;
}