HDU 1398 Square Coins

來源:互聯網
上載者:User

標籤: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;} 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.