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 ...
随机推荐
- jquery实现表格中点击相应行变色功能
对于一个表格,为了使我们选中的项更容易区分,需要为选中项添加高亮,同时也需要,将其他项的高亮形式去除.类似于: <!DOCTYPE html> <html lang="en ...
- Array(数组)与Json String (Json字符串) 的相互转换
1.Array转换成Json String function jsonToString(arr) { var s = ""; ...
- ajax案例源码
html文件中demo2_index.html ---------------------------------------------------------------------------- ...
- nginx配合modsecurity实现WAF功能
一.准备工作 系统:centos 7.2 64位.nginx1.10.2, modsecurity2.9.1 owasp3.0 1.nginx:http://nginx.org/download/ng ...
- web api post注意事项
黄色笑话 近期一个项目需要使用到web api 在使用过程中,对应get请求方式的使用基本没出什么问题 但是对于post请求状况百出. 今将遇到的的问题列出.以作借鉴. 问题 -----post方式 ...
- Spark调优
因为Spark是内存当中的计算框架,集群中的任何资源都会让它处于瓶颈,CPU.内存.网络带宽.通常,内存足够的情况之下,网络带宽是瓶颈,这时我们就需要进行一些调优,比如用一种序列化的方式来存储RDD来 ...
- 我的Fitbit Force手环使用体验
2013年底,从淘宝上代购了Fitbit Force二代,下手前也对比了当时的几个类似产品,好像记得Nike新款暂时在国内还买不到,就买下了这个,1020元,时至今日好像只需六.七百了.当时看中它的主 ...
- 发布的时候Archive灰色
主要是因为发布的时候要选为将模拟器选择一下,选为Generic iOS Device. 来自为知笔记(Wiz)
- 异步get请求之Block方法
#import "ViewController.h" #import "Header.h" @interface ViewController ()<NS ...
- CSS 伪类和伪对象选(五)
一.伪选择器 伪选择器包括:伪类选择器和伪对象选择器,以冒号(:)作为前缀,冒号后紧跟伪类或者伪对象名称,冒号前后没有空格,否则解析为包含选择器 如: div:hover{ font-size:12p ...