解题心得:

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. 性能测试学习第十天_controller

    集合点设置 controller虚拟多个用户执行脚本启动步骤不一定同步,集合点在脚本的某处设置一个标记,当有虚拟用户运行到这个标记的时候,停下等待所有用户都达到这个标记,再一同进行下面的步骤.这样可以 ...

  2. web.config文件executionTimeout的单位

      executionTimeout:表示允许执行请求的最大时间限制,单位为秒

  3. 客户端设置WebService调用超时时间

    刚接触WebService,对如何在客户端设置WebService调用超时时间查阅了一些资料,现总结如下: ============================================== ...

  4. java 基础 01 变量和注释、数据类型

    1,变量和注释 比如:姓名:xiaoming 年龄:18 1.1变量的基本概念 当需要在程序中记录单个数据内容时,则需要声明一个变量来处理,而变量的本质就是内存中申请一块存储单元用于存储数据内容,由于 ...

  5. Sublime常用插件安装大全

    作为前端人员,要找一个很顺手的编辑器真的不容易,我向大家推荐的一款实用前端开发神器,不但占地小,且插件很多,很强大. 下面我向大家介绍一下它的安装及插件的使用方法. 一.安装及安装emmet插件 首先 ...

  6. weexpack 创建项目, 打包Android 和 ios

    1: 首先确保 node.js版本大于6.0, 不然使用 weexpack 时会报错(部分使用es6语言,node版本太低不支持es6) 下面所有都是命令行执行的命令 2: 全局安装 weexpack ...

  7. bank conflct 一句话总结

    由于最新的多播模式区别于原来的广播模式,原来同一个warp不同线程访问同一个bank的相同地址不再是bank conflict, 现在总结为:只要同一个 warp 的不同线程会访问到同一个 bank ...

  8. Java Web中web.xml文件简单介绍

    参考博客: https://www.cnblogs.com/Y-oung/p/8401549.html 1.XML 声明和根元素 <?xml version="1.0" en ...

  9. oracle 的启动与连接

    1. Oracle的启动 oracle的服务如下图所示: 启动oracle有两个重要的服务(如上图标识处): l OracleOraDb11g_home1TNSListener:监听服务,主要用于客户 ...

  10. python_38_try-except异常处理语句及raise的使用

    # i=10 # print(30/(i-10)) # #程序将会出现以下报错信息 # # Traceback (most recent call last): # # File "C:/U ...