首页 > 代码库 > HDU 1398 Square Coins
HDU 1398 Square Coins
/*
中文翻译:在一个银国度里面,人们不仅有正方形的银币,而且他们的价值观是平方的, 硬币的所有面值的平方不会超过17的平方,如面值为1、4、9.。。。289面值的硬币。有四种支付方式,使总额达到10。
题目大意:求输入一个数,有多少中支付的方式
解题思路:母函数求解
难点详解:由于它是数的平方,所以在求得时候,k应该写成k+=i*i;
关键点:读懂题意,有一点小的升华
解题人:lingnichong
解题时间:2014-08-09 10:16:11
解题感受:注意是写的多少的平方,所以后面写k的变化的时候就要加上i*i。
*/
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8145 Accepted Submission(s): 5531
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.
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<stdio.h> #include<string.h> #define MAXN 300+10 int c1[MAXN],c2[MAXN]; int main() { int n,i,j,k; while(scanf("%d",&n),n) { memset(c2,0,sizeof(c2)); for(i=0;i<=n;i++) c1[i]=1; for(i=2;i<=n;i++) { for(j=0;j<=n;j++) for(k=0;k+j<=n;k+=i*i) c2[k+j]+=c1[j]; for(j=0;j<=n;j++) { c1[j]=c2[j]; c2[j]=0; } } printf("%d\n",c1[n]); } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。