杭电acm1398
母函数,见杭电acm1028
#include <stdio.h> int main() { int n, i, j, k; int ans[301], temp[301]; while(~scanf("%d", &n) && n) { for(i=0; i<=n; i++) { ans[i] = 1; temp[i] = 0; } for(i=2; i*i<=n; i++) { for(j=0; j<=n; j++) for(k=0; k+j<=n; k+=i*i) temp[k+j] += ans[j]; for(j=0; j<=n; j++) { ans[j] = temp[j]; temp[j] = 0; } } printf("%d\n", ans[n]); } return 0; }