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 Studio 优化之路

    改动keymap 改动经常使用的快捷键 代码补全(Eclipse: ALT+/) Android Studio中默认用的是Ctrl+Space, 这跟输入法切换冲突.找到Keymap->Main ...

  2. GPIO简介

    GPIO(General Purpose I/O Ports)意思为通用输入/输出端口,通俗地说,就是一些引脚,可以通过它们输出高低电平或者通过它们读入引脚的状态-是高电平或是低电平. GPIO口一是 ...

  3. [TypeScript] Transform Existing Types Using Mapped Types in TypeScript

    Mapped types are a powerful and unique feature of TypeScript's type system. They allow you to create ...

  4. TinyXml 与 Rapidxml效率对照

    曾经在做开发中一直使用TinyXml,在网上搜索说Rapidxml的效率比tinyXml高.个人比較喜欢追求效率.所以忍不住尝试性使用Rapidxml. RapidXml 的官方站点例如以下: htt ...

  5. 在CentOS上把MySQL从5.5升级到5.6

    在CentOS上把MySQL从5.5升级到5.6 摘要:本文记录了在CentOS 6.3上,把MySQL从5.5.28升级到5.6.19的过程. 1. 概述 在我做的一个项目中,最近我对生产服务器上的 ...

  6. Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...

  7. ubuntu查看文件的权限

    查看linux文件的权限: 查看path路径下名为filename的文件或文件夹的权限: ls -l path/filename ls -l path/filename 查看path路径下的所有文件的 ...

  8. Semantic Parsing(语义分析) Knowledge base(知识图谱) 对用户的问题进行语义理解 信息检索方法

    简单说一下所谓Knowledge base(知识图谱)有两条路走,一条是对用户的问题进行语义理解,一般用Semantic Parsing(语义分析),语义分析有很多种,比如有用CCG.DCS,也有用机 ...

  9. javaScript改变HTML

    改变HTML输出流: 在JavaScript中,document.write() 可用于直接向HTML输出流写内容 <!DOCTYPE html> <html> <bod ...

  10. JS窗口

    <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', 'heigh ...