hdoj-1398-Square Coins
2016-05-20 15:15
232 查看
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
Sample Output
母函数模板题
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
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define maxn 302 int num1[300]; int num2[300]; void init() { for(int i=0; i<maxn; i++) { num1[i]=1; num2[i]=0; } for(int i=2; i<=17; i++) { for(int j=0; j<maxn; j++) for(int k=0; k+j<maxn; k+=i*i) { num2[k+j]+=num1[j]; } for(int i=0; i<maxn; i++) { num1[i]=num2[i]; num2[i]=0; } } } int main() { int n; init(); while(scanf("%d",&n),n) { printf("%d\n",num1 ); } return 0; }
母函数模板题
相关文章推荐
- 设置TextView文字居中
- JAVA中去掉空格换行符回车等
- pythonchallenge 解谜 Level 5
- bootstrap 学习片段
- 中断调用与子程序设计实验
- Java时间
- JAVA之老马识途
- apache lucene core
- Android内存泄露自动检测LeakCanary
- xml:schema详解
- 程序员最常见的谎话,你说了哪一句?
- HDU_ACM_1202
- 一个有关package的错误: 没有包名的类
- BZOJ 4196 软件包管理器
- (转)Web Service入门简介(一个简单的WebService示例)
- MySQL密码的恢复方法
- ArrayList类注意事项
- Mongo数据库 Windows环境架设
- 葡萄牙寻求豁免欧盟国家援助规则以帮助银行
- [sensor]如何解决光感不灵敏的问题