HDU 1398 Square Coins

完全背包

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int A[20];
int dp[305];

int main()
{
    int i,j;
    for(i=1;i<=17;i++) A[i]=i*i;
    dp[0]=1;
    for(i=1;i<=17;i++)
        for(j=A[i];j<=300;j++)
            dp[j]=dp[j]+dp[j-A[i]];
    while(1)
    {
        int n;
        scanf("%d",&n);
        if(n==0) break;
        printf("%d
",dp[n]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/4649320.html