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
版权声明:本文为博主原创文章,转载请附上博文链接!

每一种硬币可以无限次使用

  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. #define MAX 301
  5. int n,a[MAX],b[MAX],i,j,k,v[];
  6. int main()
  7. {
  8. for (i=;i<=;i++)
  9. v[i]=i*i;
  10. while ((cin>>n)&&n>)
  11. {
  12. memset(a,,sizeof(a));
  13. a[]=;
  14. for (i=;i<=;i++)
  15. {
  16. memset(b,,sizeof(b));
  17. for (j=;j*v[i]<=n;j++)
  18. for (k=;k+j*v[i]<=n;k++)
  19. b[k+j*v[i]]+=a[k];
  20. memcpy(a,b,sizeof(b));
  21. }
  22. cout<<a[n]<<endl;
  23. }
  24. return ;
  25. }

杭电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. taglib标签在web.xml文件中报错的解决办法

    报错的原因分析: 在jsp2.0中,且2.4版的DTD验证中,taglib描述符,正确写法是放到<jsp-config></jsp-config>描述符中.所以,我们的tagl ...

  2. 静态页面HTML中标签的优化(转)

    静态页面HTML中标签的优化 (2010-04-03 20:54:06) 标签: 电脑 name 罗马数字 css 表单 杂谈 分类: 网页制作 从网上看了一篇关于静态页面中标签优化的问题,感觉还不错 ...

  3. Spring_02 注入类型值、利用引用注入类型值、spring表达式、与类相关的注解、与依赖注入相关的注解、注解扫描

    注意:注入基本类型值在本质上就是依赖注入,而且是利用的set方式进行的依赖注入 1 注入基本类型的值 <property name="基本类型的成员变量名" value=&q ...

  4. elasticsearch 6.2.4 安装 elasticsearch-analysis-ik 分词器 (windows 10下)

    访问 https://github.com/medcl/elasticsearch-analysis-ik  找 releases 找到对应的 es 版本 下载 elasticsearch-analy ...

  5. setex()

    设置值和有效期 $redis->setex($key, $expire, $value);//$expire,有效期,单位秒 相当于 SET key value//设置键值 EXPIRE key ...

  6. GitHub Pages搭建博客HelloWorld版

    1.原理 GitHub作为博客相关文件的托管方,你把按照jekyll规定的目录及文件上传至github库中,通过约定的库名称即可访问到经过jekyll渲染后的博客页面. 2.搭建过程 2.1.注册Gi ...

  7. C#与数据库访问技术总结(三)之 Connection对象的常用方法

    说明:前面(一)(二)总结了数据库连接的概念以及连接数据库的字符串中的各个参数的含义.这篇随笔介绍connection对象的常用方法. Connection对象的常用方法 Connection类型的对 ...

  8. asp.net core 之多语言国际化自定义资源文件

    先说说 asp.net core 默认的多语言和国际化. 官方文档 一:基本使用方法 先要安装 包 Microsoft.AspNetCore.Mvc.Localization (依赖 Microsof ...

  9. 循环对XML文档添加Attribute以及移除Element

    如下面的图片要求,需要把左边的xml文改为右边的文档. 需要添加Attribute,移除Element,但是所添加的Attribute值已经跟被移除的Element值不相同.实现方法可以参考<对 ...

  10. java24种设计模式

    一.设计模式定义 设计模式(Design Pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结,使用设计模式是为了可重用代码.让代码更容易被他人理解并且保证代码可靠性. ...