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. 昨天的笔试题, StringBuffer

    代码: public static void switchStr(StringBuffer x, StringBuffer y) { x.append(y); System.out.println(& ...

  2. saltstact的安装与配置

    Saltstack是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,人们一般习惯把saltstack比作成简化版的puppet和加强版的func.saltstack基于Pytho ...

  3. How to watch property in attrs of directive

    Q: I have a controller that has a counter that changes from time to time. That counter is tied to an ...

  4. jetty分析

    jetty处理过程: 1  new Server() (1)初试化线程池  生成固定大小线程数,新来的线程放入BlockingQueue. (2)初始化ServerConnector 初始化 sche ...

  5. JavaScript 书籍推荐(转)

    作者:宋学彦链接:https://www.zhihu.com/question/19713563/answer/23068003来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  6. css知多少(8)——float上篇(转)

    1. 引言 对于我们所有的web前端开发人员,float是或者曾经一度是你最熟悉的陌生人——你离不开它,却整天承受着它所带给你的各种痛苦,你以为它很简单就那么一点知识,但却驾驭不了它各种奇怪的现象. ...

  7. php验证是否建立数据库,否,则自动建立

    <?php /* 默认建立的数据库为test,数据表为admin,管理员只需要修改DB_PWD(即本地的服务器密码)即可,用户密码采用md5加密 */ define(DB_HOST," ...

  8. Spring集成MyBatis01 【推荐使用】、springMVC中文乱码和json转换问题

    1 导包 1.1 spring-webmvc : spring框架包(当然里面也包含springmvc) 1.2 mybatis : mybatis框架包 1.3 mybatis-spring : s ...

  9. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-001分析步骤

    For many programs, developing a mathematical model of running timereduces to the following steps:■De ...

  10. Python程序设计3——字典

    1 字典 字典是Python唯一内建的映射类型.字典是键值对的集合. 1.1 字典的使用 某些情况下字典更加好用,比如一个电话列表.注意:电话号码只能用字符串数字表示,否则会出问题.因为电话号码一旦以 ...