题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398

看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币,组成价值为j的价格的方案数,转移枚举第i种硬币用多少个就好了。

#include<bits/stdc++.h>
using namespace std;

const int maxn=305;
int dp[18][maxn];

int main()
{
    for (int i=1;i<=17;i++)
    {
        for (int j=1;j<=300;j++)
        {
            // i*i coin
            dp[i][j]=dp[i-1][j];
            for (int k=1;;k++)
            {
                if (i*i*k>=j) break;
                dp[i][j]+=dp[i-1][j-i*i*k];
            }
            if (j%(i*i)==0) dp[i][j]++;
        }
    }
    int n;
    while (~scanf("%d",&n) && n)
    {
        printf("%d\n",dp[17][n]);
    }
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-12-19
猜你喜欢
  • 2021-12-21
  • 2021-07-25
  • 2022-01-18
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案