hdu 1398 Square Coins

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1398

解题思路:

母函数。。。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int c1[305],c2[305];

int main(){
    int a[18];
    for(int i = 1; i <=17; i++)
        a[i] = i*i;
    int n;
    while(scanf("%d",&n),n){
        for(int i = 0; i <= n ;i++){
            c1[i] = a[1];
            c2[i] = 0;
        }
        for(int i = 2; i <= 17; i++){
            for(int j = 0; j <= n; j++)
                for(int k = 0; k*a[i] + j <= n; k++)
                    c2[k*a[i]+j] += c1[j];
            for(int j = 0; j <= n; j++){
                c1[j] = c2[j];
                c2[j] = 0;
            }
        }
        printf("%d\n",c1[n]);
    }
    return 0;
}


你可能感兴趣的:(母函数)