码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1398 Square Coins

时间:2014-08-09 11:42:57      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   java   os   io   strong   for   

/*
中文翻译:在一个银国度里面,人们不仅有正方形的银币,而且他们的价值观是平方的, 硬币的所有面值的平方不会超过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.
 

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;
} 



HDU 1398 Square Coins,布布扣,bubuko.com

HDU 1398 Square Coins

标签:des   style   color   java   os   io   strong   for   

原文地址:http://blog.csdn.net/qq_16767427/article/details/38454069

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!