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

一个很标准的母函数题目,唯一需要改变的就是把+i写成+i*i 因为题意是平方倍的增加

#include<stdio.h>
#include<iostream>
using namespace std;
int n;
int a[],b[];
int main()
{
while(cin>>n)
{ if(n==) break;
for(int i=;i<=n;i++)
{
a[i]=;
b[i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
for(int k=;k+j<=n;k+=i*i)
{
b[k+j]+=a[j];
}
}
for(int z=;z<=n;z++)
{
a[z] = b[z];
b[z] = ;
}
}
cout<<a[n]<<endl;
}
return ;
}

HDU1398 Square Coins的更多相关文章

  1. HDU1398 Square Coins(生成函数)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  2. HDU-1398 Square Coins(生成函数)

    题意 与$hdu1028$类似,只不过可用的数字都是平方数. 思路 类似的思路,注意下细节. 代码 #include <bits/stdc++.h> #define DBG(x) cerr ...

  3. hdu1398 Square Coins(母函数)

    题目类似于整数拆分,很明显用母函数来做. 母函数的写法基本固定,根据具体每项乘式的不同做出一些修改就行了.它的思路是从第一个括号开始,一个括号一个括号的乘开,用c1数组保存之前已经乘开的系数,即c1[ ...

  4. Square Coins[HDU1398]

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

  5. HDU1398:Square Coins(DP水题)

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

  6. hdu 1398 Square Coins (母函数)

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

  7. hdu 1398 Square Coins(简单dp)

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

  8. HDOJ 1398 Square Coins 母函数

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

  9. Square Coins(母函数)

    Square Coins 点我 Problem Description People in Silverland use square coins. Not only they have square ...

随机推荐

  1. 【263】Linux 添加环境变量 & 全局 shell 脚本

    Linux电脑添加环境变量 方法一:通过修改 profile 文件添加环境变量 1. 打开终端,输入[vi /etc/profile],如下所示,点击回车 [ocean@ygs-jhyang-w1 L ...

  2. android tween动画和Frame动画总结

    tween  动画有四种 //透明度动画 AlphaAnimation aa = (AlphaAnimation) AnimationUtils.loadAnimation(MainActivity. ...

  3. [patl2-007]家庭房产

    题目大意:求并查集中集合的个数,及每个集合的详细信息 解题关键:只要不进行unite,集合的根是不会变化的. #include<cstdio> #include<cstring> ...

  4. eclipse中安装git插件

    1 安装及配置git插件,问度娘即可 点击前往 2 eclipse 中怎么同步到 本地git仓库 和 码云远程仓库 点击前往

  5. R: 关于文件 文件夹的处理:file.show() dir.create().....

    文件管理主要函数: setwd( ):设定R软件当前工作目录.getwd( ):查看R软件当前工作目录.list.files( ): 查看当前目录下文件.file.show( ): 显示文件.file ...

  6. 100197G Robbers

    传送门 题目大意 看式子懂题意系列... 分析 自然想到我们先按比例下取整得到一个值,再按每个人这样分配所产生的值从大到小排序,然后将剩下的几个金币自大到小每人分配一个,代码挺好理解的,详见代码. 代 ...

  7. kaggle Partial_Dependence_Plots

    # Partial dependence plots# 改变单变量对最终预测结果的影响# 先fit出一种模型,然后取一行,不断改变某一特征,看它对最终结果的印象.# 但是,只使用一行不具有典型性# 所 ...

  8. 《Head First Servlets & JSP》-4-请求和响应

    Servlet生命周期 生命周期三大重要时刻 Servlet集成结构: 方法 init() service() doGet()/goPost() 何时调用 Servlet实例被创建之后.为客户请求提供 ...

  9. 多线程学习-基础( 九)线程同步Synchronized关键字

    一.线程同步1.synchronized关键字的作用域有二种:(1)某个对象实例内:synchronized aMethod(){}可以防止多个线程同时访问这个对象的synchronized方法(如果 ...

  10. 共享库so

    so文件在linux中为共享库,与windows下的dll类似. so文件中的函数可供多个进程调用,最大可能的提供二进制代码的复用. 共享库可以使代码的维护工作大大简化,当修正了一些错误或者添加了新特 ...