注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU1398 Square Coins  

2014-04-18 22:14:28|  分类: 母函数 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Square Coins

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



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

 


Source


 


Recommend

Ignatius.L   |   We have carefully selected several
similar problems for you:  1171 1085 2152 2082 1709 

 

#include <iostream>
#include<fstream>
using namespace std;
int a1[300],a2[300];
void building()
{
int i,j,k;
for(i=0;i<=300;i++)
{
a1[i]=1;
a2[i]=0;
}
for(i=2;i<=17;i++)
{
for(j=0;j<=300;j++)
{
for(k=0;k+j<=300;k+=i*i)
{
a2[j+k]+=a1[j];
//cout<<a2[j+k]<<" jj"<<endl;
}
}
for(j=0;j<=300;j++)
{
a1[j]=a2[j];
// cout<<a1[j]<<endl;
a2[j]=0;
}
}
}
int main()
{
int N;
//ifstream cin("aa.txt");
building();
while(cin>>N)
{
if(N==0) break;
cout<<a1[N]<<endl;
}
return 0;
}


  评论这张
 
阅读(3)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017