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
解题思路:多种硬币(有币值为1^2,2^2,...,17^2共17种硬币)的组合!解法和此篇博文类似:题解报告:hdu 1284 钱币兑换问题(简单数学orDP)
AC代码一之dp(0ms):
 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,dp[]={};
for(int i=;i<=;++i)//预处理打表
for(int j=i*i;j<;++j)
dp[j]+=dp[j-i*i];
while(cin>>n&&n){cout<<dp[n]<<endl;}
return ;
}

AC代码二之母函数(15ms):生成函数G(x)=(1+x^1+x^2+...)(1+x^4+x^8+x^12+...)(1+x^9+x^18+...)(...)(1+x^289)。

 #include<bits/stdc++.h>
using namespace std;
int n,c1[],c2[];
void init(){
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
c1[]=;//指数为0的系数为1
for(int i=;i<=;++i){
for(int j=;j<=;++j)
for(int k=;k+j<=;k+=i*i)
c2[k+j]+=c1[j];
for(int j=;j<=;++j)
c1[j]=c2[j],c2[j]=;
}
}
int main(){
init();
while(~scanf("%d",&n)&&n){printf("%d\n",c1[n]);}
return ;
}

题解报告:hdu 1398 Square Coins(母函数或dp)的更多相关文章

  1. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  3. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  5. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  6. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  7. HDOJ 1398 Square Coins 母函数

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. 杭电ACM hdu 1398 Square Coins

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  9. HDU 1398 Square Coins(DP)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. android 自己定义水平和圆形progressbar 仅仅定义一些style就能够

    效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  2. 广东IP段列表

    广东IP段列表219.137.240.0 219.137.240.255219.137.148.0 219.137.150.255 广东省广州市 电信ADSL219.137.144.0 219.137 ...

  3. 工作总结 使用html模板发邮件 前面空一大块

    HTML邮件的本质其实是发送了一个html页面.邮件的空白必然是页面的空白,所以你要找到你发送邮件的html模板所在,然后去掉空白即可,如果这是一个公共文件,需要注意你往往用的只是你的部分,很大程度还 ...

  4. C# 性能优化 之 秒表 Stopwatch。 Dapper一个和petapoco差不多的轻量级ORM框架

    Sweet小马 小马同学的编程日记. C# 性能优化 之 秒表 Stopwatch. 生词解释:Diagnostics[,daɪəg'nɑstɪks] n.诊断学 using System.Diagn ...

  5. MongoDB 操作手冊CRUD 更新 update

    改动记录 概述 MongoDB提供了update()方法用于更新记录. 这种方法接受下面參数:     一个更新条件的JSON对象用于匹配记录,一个更新操作JSON对象用于声明更新操作,和一个选项JS ...

  6. 自定义的强大的UITableViewCell

    UITableView的强大更多程度上来自于可以任意自定义UITableViewCell单元格.通常,UITableView中的Cell是动态的,在使用过程中,会创建一个Cell池,根据每个cell的 ...

  7. adb端口被占用情况下如何杀掉进程

    1.CMD命令窗口输入:adb nodaemon server .然后就会提示你哪个端口被占用了. 2.输入netstat -ano | findstr "5037" .然后会弹出 ...

  8. onDestroy强制退出后,process crash的处理

    from http://bbs.9ria.com/thread-248722-1-1.html     一般情况,我们在执行测试的过程中都会调用tearDwon方法,以Robotium为例,我们在te ...

  9. break return continue

    1.return 语句的作用 (1) return 从当前的方法中退出,返回到该调用的方法的语句处,继续执行 (2) return 返回一个值给调用该方法的语句,返回值的数据类型必须与方法的声明中的返 ...

  10. Koa2学习(三)GET请求

    Koa2学习(三)GET请求 GET请求是前后端交互最常用的请求之一,常常用来进行查询操作. 那么Koa是如何接收并处理GET请求呢? 创建一个服务 // 引入Koa const Koa = requ ...