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. Linux信号通讯编程

    信号通讯流程为: ①进程A/内核选择信号 ②发送信号 ③进程B接收信号并处理 Linux系统支持的全部信号均定义在/usr/include/asm/signal.h.当中常见的信号有: ①SIGKIL ...

  2. Zookeeper中的FastLeaderElection选举算法简述

    Zookeeper是一个开源的分布式应用协调项目, 当中为了保证各节点的协同工作,Zookeeper在工作时须要有一个Leader. 而Leader是怎样被选举出来的?Zookeep中使用的缺省算法称 ...

  3. cocos2dx 制作单机麻将(五)

    cocos2dx 制作单机麻将(五) 麻将逻辑6 最基础的4人麻将逻辑(轮流循环出牌, 之前学的都能用上  跑起来了!!!) 最基础的麻将逻辑 依据自己须要 设置麻将人数GAME_PLAYER 基本流 ...

  4. DLR之 ExpandoObject和DynamicObject的使用演示样例

    ExpandoObject :动态的增删一个对象的属性,在低层库(比如ORM)中非常实用.因为ExpandoObject实现了IDictionay<string, object>接口,常见 ...

  5. 包管理 import debug 模块管理 module

    import sys, os this_file_abspath = os.path.dirname(os.path.abspath(__file__)) ProjectUtil_path = '{} ...

  6. Deep Learning 28:读论文“Multi Column Deep Neural Network for Traffic Sign Classification”-------MCDNN 简单理解

    读这篇论文“ Multi Column Deep Neural Network for Traffic Sign Classification”是为了更加理解,论文“Multi-column Deep ...

  7. Golang1.8编译静态库给C使用

    Go实例代码: package main import ( "fmt" ) import "C" //export Printf func Printf(for ...

  8. linux CANopenSocket 初试

    /************************************************************************************** * linux CANo ...

  9. URAL2104. Game with a Strip(博弈)

    There is a strip 1 × n with two sides. Each square of the strip (their total amount is 2n, n squares ...

  10. AutoIT: ControlSetText

    1. ControlSetText :可以摆脱Send的限制,在适当的文本框位置输入用户想要输入的信息.2. ControlGetText可以获取文本 Run("notepad.exe&qu ...