杭电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输入 ...
随机推荐
- NULL、0、nullptr
C的NULL 在C语言中,我们使用NULL表示空指针,也就是我们可以写如下代码: int *i = NULL;foo_t *f = NULL; 实际上在C语言中,NULL通常被定义为如下: #defi ...
- go get
go get 命令用于从远程代码仓库(比如 Github )上下载并安装代码包.注意,go get 命令会把当前的代码包下载到 $GOPATH 中的第一个工作区的 src 目录中,并安装. 如果在 g ...
- MyBatis02 MyBatis基础知识之Mapper映射器
1 Mapper映射器是什么 是符合映射文件要求的接口 接口要求 a. 方法名要与sql的id一致. b. 方法的参数类型要与parameterType一致. c. 方法的返回类型要与resultTy ...
- Tensorflow fetch和feed
import tensorflow as tf #Fetch input1 = tf.constant(1.0)input2 = tf.constant(3.0)input3 = tf.constan ...
- ROS Learning-023 (提高篇-001) 准备工作 --- 安装一些必要的软件包
ROS 提高篇-001 - 准备工作 - 安装一些必要的软件 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04.4 LTS ROS 版本 ...
- VMware内部错误解决办法
虚拟机内部错误,不要担心不是致命错误,往往是由于你的配置被禁用了或者VMware运行权限不够导致 检查你的VMware虚拟网卡是否被禁用 检查你的VMware的运行权限,直接管理员运行就够够的了
- Java-马士兵设计模式学习笔记-工厂模式-模拟Spring读取Properties文件
一.目标:读取properties文件,获得类名来生成对象 二.类 1.Movable.java public interface Movable { void run(); } 2.Car.java ...
- Android 之 信息通知栏消息Notification
Notification是安卓手机顶部的消息提示 这里我们分别设置两个按钮,来实现顶部消息的发送和取消 功能实现 首先要在主Activity中设置一个通知控制类 NotificationManager ...
- delphi xe6 调用java GPS的方法
如果用xe6自带的LocationSensor控件,默认优先使用网络位置,网络位置定位精度不准确,不能满足高精度定位的要求.但xe6自带的LocationSensor控件不能指定网络定位优先还是GPS ...
- 文本PDG文件名构成
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2008.08.03 文本PDG的构成规则为:<前缀><起始页号>_<页数>.pdg 前缀 ...