標籤: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 CoinsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8145 Accepted Submission(s): 5531
Problem DescriptionPeople 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.
InputThe 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.
OutputFor 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
210300
Sample Output
1427
#include<stdio.h>#include<string.h>#define MAXN 300+10int 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;}