杭电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输入 ...
随机推荐
- sqlplus--spool命令参数详解
sqlplus--SPOOL参数详解 Spool是Oracle快速导出数据的工具,是sqlplus的指令,不是sql语法里的东西 一.Spool常用的设置set arraysize 5000; // ...
- JavaScript的作用域与闭包
JavaScript的作用域以函数为界,不同的函数拥有相对独立的作用域.函数内部可以声明和访问全局变量,也可以声明局部变量(使用var关键字,函数的参数也是局部变量),但函数外部无法访问内部的局部变量 ...
- vue mock数据设置
1.新建mock文件夹 2.添加你需要的数据例如新建商品表goods.json { "status":"0", "result":[ { & ...
- php的变量引用详解
<?php class SimpleClass { // property declaration public $var = 'a default value'; // method decl ...
- C语言-郝斌笔记-003数据类型
基本类型数据 整数 整型 —— int --4字节 短整型 —— short int ——2字节 长整型 —— long int ——8字节 浮点数[实 ...
- Entity Framework Tutorial Basics(28):Concurrency
Concurrency in Entity Framework: Entity Framework supports Optimistic Concurrency by default. In the ...
- 发现C#winform编程中不常用的控件(一)<FlowLayoutPanel控件><拆分器控件Splitcontainer >
第一部分:FlowLayoutPanel控件 实现效果: 将FlowLayoutPanel做为导航菜单按钮的容器 以实现 某个菜单按钮不显示时 整体的导航菜单布局不至于"缺憾" 原 ...
- 《Maven实战》笔记-4-生命周期和插件
除了坐标.依赖以及仓库外,Maven另外两个核心概念是生命周期和插件. 一.生命周期 Maven的生命周期是抽象的,其本身不做任务实际的工作,实际的任务(如编译源代码)都交由插件来完成. 三套生命周期 ...
- php数据连接
<?php header("Content-type: text/html;charset=utf-8");//设置编码格式为UTF-8 error_reporting(E_ ...
- 【C#】如何打开Model Browser(实体数据模型浏览器)
Visual Studio 2017 如何打开Model Browser(实体数据模型浏览器) 2017-10-11 十有三 2 浏览:4956 开发工具 Visual Studio 做个笔记,记录下 ...