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的更多相关文章

  1. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  2. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  3. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  5. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  6. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  7. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. HDU 1398 Square Coins(DP)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  9. 杭电ACM hdu 2079 选课时间 (模板)

    Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别) Input输入 ...

随机推荐

  1. Android 自定义Camera 随笔

      一.权限 <uses-permission android:name="android.permission.CAMERA" /> <uses-permiss ...

  2. CSS技巧: CSS隐藏文字的方法(CSS text-indent: -9999px;)

    建站过过程中朋友喜欢把网站名称用H1表示,但从美观考虑,要用logo图片来代替h1,这时需要隐藏h1内的这段文字,但又不能对搜索引擎不友好,否则就失去了定义h1标签的意义. 在CSS中如何以图代字,找 ...

  3. 关于c#数据类型,类型转换,变量,常量,转义符。。。

    先说一下数据类型...数据类型可以分为两大类:基本数据类型和引用类型. 基本数据类型按功能又分为“值类型”,“布尔型”,“字符型”. 引用类型分为“字符串”,“时间日期”.  没图没真相↓面放图. 橙 ...

  4. R: 字符串处理包:stringr

    本文摘自:  http://blog.fens.me/r-stringr/ 1. stringr介绍 stringr包被定义为一致的.简单易用的字符串工具集.所有的函数和参数定义都具有一致性,比如,用 ...

  5. Linux网络配置常用命令

    计算机需要网络连接才能和其他计算机通信,这是通过操作系统识别接口卡(如以太网卡.猫等等),并配置该接口以连接到网络上来实现的.网络配置命令可以用来配置以下类型的网络接口:以太网.ISDN(综合业务数字 ...

  6. WebGoat系列实验Injection Flaws

    WebGoat系列实验Injection Flaws Numeric SQL Injection 下列表单允许用户查看天气信息,尝试注入SQL语句显示所有天气信息. 选择一个位置的天气,如Columb ...

  7. win7 64位 [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认

    问题描述: VBA程序连接Access数据库,Excel中执行相关宏,提示[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认 解决方案: 1.重新安装 AccessDa ...

  8. PHP常用的服务器

    Wordpress够流行了吧,它是一个用PHP编写的强大的博客平台.使用它来架设一个博客平台相关容易,是新手建站比较方便的工具.但是要真正体会Wordpress(以下简称WP)强大,插件是不可少的东西 ...

  9. android报错:org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject

    今天在写一个webservice时一直报错,报Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast ...

  10. CentOS 6.7中安装python3.5

    1.安装一些依赖的软件包 yum groupinstall "Development tools" yum install zlib-devel bzip2-devel opens ...