HDU1398 Square Coins(生成函数)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13791 Accepted Submission(s):
9493
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.
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.
single integer representing the number of combinations of coins should be
output. No other characters should appear in the output.
10
30
0
4
27
#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(生成函数)的更多相关文章
- HDU-1398 Square Coins(生成函数)
题意 与$hdu1028$类似,只不过可用的数字都是平方数. 思路 类似的思路,注意下细节. 代码 #include <bits/stdc++.h> #define DBG(x) cerr ...
- HDU1398 Square Coins
Description People in Silverland use square coins. Not only they have square shapes but also their v ...
- hdu1398 Square Coins(母函数)
题目类似于整数拆分,很明显用母函数来做. 母函数的写法基本固定,根据具体每项乘式的不同做出一些修改就行了.它的思路是从第一个括号开始,一个括号一个括号的乘开,用c1数组保存之前已经乘开的系数,即c1[ ...
- Square Coins[HDU1398]
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU1398:Square Coins(DP水题)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ 1398 Square Coins
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
随机推荐
- .NET开源工作流RoadFlow-流程运行-调试
我们在设计好流程后,往往要先经过测试,把整个流程走遍,但是一个流程要多人审批才能走完,这样换别人账号来测试流程很麻烦. 所以我们设计了一种调试模式,即可以在流程运行时看到相关信息(错误时会显示错误信息 ...
- 116.001 - 爱折腾之用 Kindle 读学术论文是什么体验?
@(116 - Kindle 使用指南) 结论先行 - 强烈安利k2pdfopt,把双栏论文转成kindle友好的pdf 整理转载自知乎@ wei huang 双栏学术论文在6寸屏上看就是个坑 新买的 ...
- radio中最佳解决方案
radio中最佳解决方案 1.html中 <td> <input id="status" name="status" type="r ...
- javax.swing.JComponent 调用顺序
网上截取的,感觉挺有用,记录下来. http://bbs.csdn.net/topics/310041707 java swing 感觉好复杂啊…………一点都不想用但是作业要用到 >_<; ...
- 天诛进阶之D算法 #3700
http://mp.weixin.qq.com/s/ngn98BxAOLxXPlLU8sWH_g 天诛进阶之D算法 #3700 2015-11-24 yevon_ou 水库论坛 天诛进阶之D算法 #3 ...
- [python错误]UnicodeDecodeError: 'gbk' codec can't decode byte...
出现此错误的原因是使用'gbk'解码时报错,存在一些字符不能使用gbk来解码. 首先,简体中文字符编码(ASCII扩展字符集)有下列几种:GB2312.GBK.GB18030. GB2312: 中国国 ...
- /usr/lib64/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team
升级python2.6到2.7后,执行ansible后一直显示警告,如标题所示. 因为安装ansible,使用的是yum的方式,而yum使用的是python2.6,所以ansible安装环境为pyth ...
- 不错的.net开源项目
Json.NET http://json.codeplex.com/ Json.Net是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用Json更加简单.通过Lin ...
- 轮播图3D效果--roundabout(兼容IE8)升级版
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 牛客网多校训练第三场 A - PACM Team(01背包变形 + 记录方案)
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai, ...