Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13791    Accepted Submission(s):
9493

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
 
Source
 
Recommend
Ignatius.L   |   We have carefully selected several
similar problems for you:  1171 1085 2152 1709 2079 
 
题目大意:
仅用价值为$i^2$的硬币,拼出$N$的方案数
 
sol:
对于每个硬币都构造生成函数$ax^i$表示价值为$i$时的方案数
全都乘起来就好
 
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAXN = ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int cur[MAXN], nxt[MAXN], now[MAXN];
int main() {
int N;
for(int i = ; i <= ; i++)
now[i] = i * i;
while(scanf("%d", &N) && N) {
memset(cur, , sizeof(cur));
for(int i = ; i <= N; i++) cur[i] = ;
for(int i = ; now[i] <= N; i++) {
for(int j = ; j <= N; j++)
for(int k = ; j + now[i] * k <= N; k++)
nxt[j + k * now[i]] += cur[j];
memcpy(cur, nxt, sizeof(nxt));
memset(nxt, , sizeof(nxt));
}
printf("%d\n", cur[N]);
}
return ;
}

HDU1398 Square Coins(生成函数)的更多相关文章

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

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

  2. HDU1398 Square Coins

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

  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. HDOJ 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)

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

  8. hdu 1398 Square Coins (母函数)

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

  9. hdu 1398 Square Coins(简单dp)

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

随机推荐

  1. hive配置参数的说明:

    hive.ddl.output.format:hive的ddl语句的输出格式,默认是text,纯文本,还有json格式,这个是0.90以后才出的新配置: hive.exec.script.wrappe ...

  2. idea引入依赖包报错

    今天在更新项目的时候,maven依赖的一个服务一直报错.查了后发现原来是因为缺少依赖包.但是依赖包明明在我本地啊. 又重新下载,依然如故... 搞了半天,发现自己的依赖包类状态都是不可用的.如下图所示 ...

  3. androidwebview timeout

    public class MyWebViewClient extends WebViewClient { boolean timeout; public MyWebView() { timeout = ...

  4. GIT团队合作探讨之一-保持工作同步的概念和实践

    感谢英文原文作者,这是我看到的关于git协同工作写的最清晰简洁的文章了: https://www.atlassian.com/git/tutorials/syncing/git-push SVN使用一 ...

  5. 从Event Loop谈JS的运行机制

    这里主要是结合Event Loop来谈JS代码是如何运行的. 事件循环对于我们平时开发可以说是特别重要,可以让我们写出更好的代码. 到这里相信我们已经知道了JS引擎是单线程,而且这里会用到前面说的的几 ...

  6. .C#认证考试试题汇编:第一单元:1,11 第二单元:1,11

    第一单元1,11 好久没用异或都快忘了,就让我们一起来了解哈啥子事异或 说的这个,就不经意让我想起书上的几种交换值得方法了 我这儿说的交换的方法是,不使用第三个变量来交换,而是两个 实现条件是C a= ...

  7. Intellij idea用快捷键自动生成序列化id

    ntellij idea用快捷键自动生成序列化id 类继承了Serializable接口之后,使用alt+enter快捷键自动创建序列化id 进入setting→inspections→seriali ...

  8. Dz7.2 从获取uc key到getshell

    0x01下午在群里看到的 问下朋友大概 然后用不生不熟的sqlmap在那跑–表能跑的出 列就GG了 然后没辙–晚上跑各大论坛逛了遍果然大神多 就慢慢的研究下了下 看了pt0n大牛的分析文 真心感叹这洞 ...

  9. 018os模块

    import   osprint(os.getcwd())   # 获取当前目录  F:\python_code\fullstack_s2\week4\day18 os.chdir(r'C:/User ...

  10. 复制collections

    use product-test; var cursor = db.user.find(); use product; while(cursor.hasNext()){db.user.insert(c ...