hdu 1398 Square Coins(简单dp)
Square Coins
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) 
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
代码:

#include <cstdio>
#include <algorithm>
using namespace std;
int dp[18][310];//dp[a][b]表示当只有小于等于a*a的硬币面值时凑成b credic有多少种情况 int main()
{
for(int i=1;i<=300;i++)
dp[1][i]=1;
for(int i=1;i<=17;i++)
dp[i][0]=1;//b=0,这时等于0好像更合理,但是下面
//dp[i][j]+=dp[i-1][j-k*i*i];,当j==k*i*i,dp[i][j]应该加1,
//故令dp[i][0]=1;
for(int i=2;i<=17;i++)
for(int j=1;j<=300;j++)
{
dp[i][j]=dp[i-1][j];
for(int k=1;j>=k*i*i;k++)
dp[i][j]+=dp[i-1][j-k*i*i];
} int n;
while(scanf("%d",&n),n)
printf("%d\n",dp[17][n]);
return 0;
}
hdu 1398 Square Coins(简单dp)的更多相关文章
- 题解报告:hdu 1398 Square Coins(母函数或dp)
		
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
 - HDU 1398 Square Coins(母函数或dp)
		
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
 - HDU 1398 Square Coins(DP)
		
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
 - hdu 1398  Square Coins 分钱币问题
		
Square Coins Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
 - hdu 1398 Square Coins (母函数)
		
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
 - hdu 1398 Square Coins(生成函数,完全背包)
		
pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...
 - HDU  1398  Square Coins  整数拆分变形 母函数
		
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
 - 杭电ACM hdu 1398 Square Coins
		
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
 - HDU 1398 Square Coins
		
题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...
 
随机推荐
- C#设计模式——访问者模式(Visitor Pattern)
			
一.概述由于需求的改变,某些类常常需要增加新的功能,但由于种种原因这些类层次必须保持稳定,不允许开发人员随意修改.对此,访问者模式可以在不更改类层次结构的前提下透明的为各个类动态添加新的功能.二.访问 ...
 - mis导入器的加强版——vdproj文件资源浏览器
			
上次做的那个导入器不够强大,限制还不小,用起来不方便.于是就再做一个这样的工具.代码基本上不同了,思想还是差不多,但功能肯定比之前的强大.经过了这次编写工具,对vdporj文件的了解又深一层了. 在v ...
 - 【百度SEO优化】如何让蜘蛛爬行你的网站
			
大家都知道,现在做网站简单,但是推广就比较困难了,可能一些商家引入投资,直接烧钱做广告来推广,但是对于一些小站长,是没有那么多资金的.因此我们就要懂得一些SEO优化的知识了,简单介绍一下: 怎么让百度 ...
 - MVC中视图View向控制器传值的方法
			
MVC中视图View向控制器传值的方法步骤如下: 1.index页面: 页面中只需要一个触发事件的按钮
 - 分享AceAdminUI后台框架-你喜欢吗?
			
距离上次写文章也很久了,这次分享一下自己刚刚看上的一款UI框架(自己买的),国外货,提供下载 第100位评论的我将会送出一个小礼物 礼物链接:http://yanghenglian.taobao.co ...
 - 【iOS】Quartz2D练习-动态改变属性值
			
一.通过slider控制圆的缩放 1.实现过程 新建一个项目,新建一个继承自UIview的类,并和storyboard中自定义的view进行关联.代码示例:SLViewController.m文件 # ...
 - .NET Framework 4.0之Tuple(元组)
			
Tuple,是函数式编程的概念之一,早见于Elang.F#等动态语言.Tuple类型像一个口袋,在出门前可以把所需的任何东西一股脑地放在里面.您可以将钥匙.驾驶证.便笺簿和钢笔放在口袋里,您的口袋是存 ...
 - LinQ实战学习笔记(三) 序列,查询操作符,查询表达式,表达式树
			
序列 延迟查询执行 查询操作符 查询表达式 表达式树 (一) 序列 先上一段代码, 这段代码使用扩展方法实现下面的要求: 取进程列表,进行过滤(取大于10M的进程) 列表进行排序(按内存占用) 只保留 ...
 - 【JavaEE】Hibernate继承映射,不用多态查询只查父表的方法
			
几个月前,我在博问里面发了一个问题:http://q.cnblogs.com/q/64900/,但是一直没有找到好的答案,关闭问题以后才自己解决了,在这里分享一下. 首先我重复一下场景,博问里面举的动 ...
 - jQuery owlcarousel 旋转木马
			
owlcarousel是一款猫头鹰旋转木马插件.OwlCarousel优势兼容所有浏览器支持响应式支持 CSS3 过度支持触摸事件支持 JSON 及自定义 JSON 格式支持进度条支持自定义事件支持延 ...