HDU 1398 Square Coins

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

大概像是01背包

#include<bits/stdc++.h>
using namespace std;
const int maxn = 400;
int dp[maxn];
int s[maxn];
void init()
{
    memset(dp,0,sizeof(dp));
}
int main ()
{
    int n;
    for(int i=1;i<=17;i++)
        s[i] = i*i;
    dp[0] =1;
    for(int i=1;i<=17;i++)
    {
            for(int j=s[i];j<=300;j++)
                dp[j] +=dp[j-s[i]];
    }
    while (~scanf("%d",&n) && n )
    {
        printf("%d
",dp[n]);
    }
}
原文地址:https://www.cnblogs.com/Draymonder/p/7360587.html