杭电ACM hdu 1398 Square Coins
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)
Recommend
Ignatius.L
原文:https://blog.csdn.net/xiaofei_it/article/details/17041815
版权声明:本文为博主原创文章,转载请附上博文链接!
每一种硬币可以无限次使用
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 301
int n,a[MAX],b[MAX],i,j,k,v[];
int main()
{
for (i=;i<=;i++)
v[i]=i*i;
while ((cin>>n)&&n>)
{
memset(a,,sizeof(a));
a[]=;
for (i=;i<=;i++)
{
memset(b,,sizeof(b));
for (j=;j*v[i]<=n;j++)
for (k=;k+j*v[i]<=n;k++)
b[k+j*v[i]]+=a[k];
memcpy(a,b,sizeof(b));
}
cout<<a[n]<<endl;
}
return ;
}
杭电ACM hdu 1398 Square Coins的更多相关文章
- hdu 1398 Square Coins 分钱币问题
Square Coins Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 题解报告: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 (母函数)
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) Pro ...
- 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 ...
- 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 ...
- 杭电ACM hdu 2079 选课时间 (模板)
Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别) Input输入 ...
随机推荐
- byte[] 的toString() 和 new String(byte[]) 的区别
今天在Android上测试压缩和解压缩. 获得压缩后的byte[]数组后,直接用 byte[].toString()方法取得字符串. 然后用这个字符串再反向来解压缩,还原数据.却发现还原回来的字符串有 ...
- springmvc 注解式开发 接收请求参数
1.校正请求参数名: 2.以对象形式整体接收 3.路径变量:
- 奇葩问题 eclipse下 maven项目 java Resource报个小红叉,然而里面却没有小红叉
之前没注意,不知是一开始就有还是这两天才有,说下解决方案: 右击项目“Properties”,在弹出的“Properties”的左侧边框,单击“Project Facets”,打开“Project F ...
- JavaScript的self和this使用小结
一.self这个非常简单.我们知道,打开任何一个网页,浏览器会首先创建一个窗口,这个窗口就是一个window对象,也是js运行所依附的全局环境对象和全局作用域对象.self 指窗口本身,它返回的对象跟 ...
- Mongo client - cross-platform MongoDB management tool
Mongo client for Ubuntu or Windows http://robomongo.org/download.html
- Amazon S3 云服务
一.简介 Amazon Simple Storage Service (S3) 是一个公开的服务,Web 应用程序开发人员可以使用它存储数字资产,包括图片.视频.音乐和文档. S3 提供一个 REST ...
- 安装postman工具模拟请求
扩展工具->: 注意,在创建快捷方式后,第一次打开这个工具,会让你注册信息,忽略它.关闭,重新打开postman工具,然后如下所示:
- <超越死亡:恩宠与勇气>节选
我有一副身体,但我并非自己的身体.我可以看见并感觉到我的身体,然而凡是可以被看见以及被感觉到的,并不是真正的观者.我的身体也许疲惫或兴奋,生病或健康,沉重或轻松,也可能焦虑或平静,但这与内在的真我全然 ...
- Java的post(HTTPS)请求-----接口测试
package com.ju.util; import java.io.BufferedReader; import java.io.IOException; import java.io.Input ...
- win10系统遇到的问题解决
1.win10 计算器提示:需要新应用打开此calculator 运行calc,会出现需要新应用打开此Calculator,打开应用商店,找到计算器,仍然可以被使用,我怀疑是我自己在清理PC的注册 ...