解题心得:

1、其实此题有两种做法,动态规划,母函数。个人更喜欢使用动态规划来做,也可以直接套母函数的模板

Square Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 12191    Accepted Submission(s): 8352

Problem Description

People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are
available in Silverland.

There are four combinations of coins to pay ten credits:

ten 1-credit coins,

one 4-credit coin and six 1-credit coins,

two 4-credit coins and two 1-credit coins, and

one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.

 

Input

The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.

 

Output

For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.

 

Sample Input

2

10

30

0

 

Sample Output

1

4

27

 

Source

Asia 1999, Kyoto (Japan)

dp:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int va[18];
for(int i=1;i<=17;i++)
{
va[i] = i*i;
}
int n;
int d[310];
for(int i=0;i<310;i++)
{
d[i] = 1;
}
for(int i=2;i<=17;i++)
{
for(int j=va[i];j<310;j++)
d[j] += d[j-va[i]];
}
while(~scanf("%d",&n))
{
if(n == 0)
break;
printf("%d\n",d[n]);
}
}

母函数:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int c1[310],c2[310];
int n;
while(scanf("%d",&n) && n)
{
for(int i=0;i<=n;i++)
{
c1[i] = 1;
c2[i] = 0;
} for(int i=2;i*i<=n;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=0;k+j<=n;k+=i*i)
c2[k+j] += c1[j];
}
for(int k=0;k<=n;k++)
{
c1[k] = c2[k];
c2[k] = 0;
}
}
printf("%d\n",c1[n]);
}
}

动态规划:HDU-1398-Square Coins(母函数模板)的更多相关文章

  1. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  3. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  4. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  6. HDOJ 1398 Square Coins 母函数

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  8. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  9. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

  10. 杭电ACM hdu 1398 Square Coins

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

随机推荐

  1. SpringBoot | 第二十六章:邮件发送

    前言 讲解了日志相关的知识点后.今天来点相对简单的,一般上,我们在开发一些注册功能.发送验证码或者订单服务时,都会通过短信或者邮件的方式通知消费者,注册或者订单的相关信息.而且基本上邮件的内容都是模版 ...

  2. BZOJ4355: Play with sequence(吉司机线段树)

    题意 题目链接 Sol 传说中的吉司机线段树??感觉和BZOJ冒险那题差不多,就是强行剪枝... 这题最坑的地方在于对于操作1,$C >= 0$, 操作2中需要对0取max,$a[i] > ...

  3. 【Quartus错误】Internal Error: Sub-system: AMERGE

    错误内容:Internal Error: Sub-system: AMERGE, File: /quartus/atm/amerge/amerge_kpt_op.cpp, Line: 220 解决方案 ...

  4. meterpreter > ps

    meterpreter > ps Process List============ PID PPID Name Arch Session User Path --- ---- ---- ---- ...

  5. VMware下Centos6.4安装

    VMware(Virtual Machine ware)是一个“虚拟PC”软件公司,提供服务器.桌面虚拟化的解决方案. 小伙伴们网上下载VMware11,一路下一步自己安装吧!!! 打开 VMware ...

  6. php使用GD库实现图片水印和缩略图——封装成类

    学完了如何使用GD库来实现对图片的各种处理,那么我们可以发现,不管哪种方法,都有相似之处,如果我们把这些相似的地方和不相似的地方都封装成类,这样就可以提升代码的速度,而且节省了很多时间,废话不多说,来 ...

  7. 【强力卸载】使用Uninstall Tool卸载各类不易卸载的软件

    Uninstall Tool 经测试卸载MySql5.7.18成功. 下载地址: http://files.cnblogs.com/files/xiaohi/%E3%80%90%E8%BD%AF%E4 ...

  8. IOS 线程描述

    ●什么是线程 ● 1个进程要想执行任务,必须得有线程(每1个进程至少要有1条线程) ● 线程是进程的基本执行单元,一个进程(程序)的所有任务都在线程中执行 ● 比如使用酷狗播放音乐.使用迅雷下载电影, ...

  9. UVA 12034 Race(递推)

    递推,f[i = i个名次][j = 共有j个人] = 方案数. 对于新加入的第j个人,如果并列之前的某个名次,那么i不变,有i个可供并列的名次选择,这部分是f[i][j-1]*i, 如果增加了一个名 ...

  10. 【洛谷】CYJian的水题大赛 解题报告

    点此进入比赛 \(T1\):八百标兵奔北坡 这应该是一道较水的送分题吧. 理论上来说,正解应该是DP.但是,.前缀和优化暴力就能过. 放上我比赛时打的暴力代码吧(\(hl666\)大佬说这种做法的均摊 ...