博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1398Square Coins(dp或者母函数)
阅读量:4049 次
发布时间:2019-05-25

本文共 1534 字,大约阅读时间需要 5 分钟。

Square Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10752    Accepted Submission(s): 7338


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
210300
 

Sample Output
1427
 

Source
 

Recommend
Ignatius.L
i表示有几种可能性   dp数组是把每种可能性累加  j表示变化规律
#include
#include
#include
using namespace std;int dp[500];int main() { int n,m,i,k,j; while(cin>>k&&k) { memset(dp,0,sizeof(dp)); dp[0]=1; n=(int)sqrt(k*1.0); for(i=1;i<=n;i++) { for(j=i*i;j<=k;j++) { dp[j]+=dp[j-i*i]; } } cout<
<

转载地址:http://gtfci.baihongyu.com/

你可能感兴趣的文章
JavaScript和Jscript的版本及规范
查看>>
WinCE 对 Java脚本的支持
查看>>
XML学习
查看>>
ASP中LIST控件
查看>>
ASP中按钮触发事件
查看>>
学习:GPIO口模拟I2C
查看>>
展望2007
查看>>
做个男人
查看>>
转:S3C2410 bootloader ----VIVI阅读笔记
查看>>
转:嵌入式系统 Boot Loader 技术内幕
查看>>
ARM 的宏定义
查看>>
SIGN UP BEC2
查看>>
S3C2440中对LED驱动电路的理解
查看>>
《天亮了》韩红
查看>>
Windows CE下USB摄像头驱动开发(以OV511为例,附带全部源代码以及讲解) [转]
查看>>
关于货币符号以及发音、币别码
查看>>
关于预处理器的学习
查看>>
ARM,S3C2410中脉宽调制定时器
查看>>
Zebra Bar-One 不能批量打印离散号码
查看>>
Platform创建WinCE内核时的编译错误
查看>>