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 ...
随机推荐
- opencv 从摄像头中读取视频并保存(c++版)
原文:http://blog.csdn.net/zhongshijunacm/article/details/68947890 OpenCV中的视频操作函数如下表所列: VideoCapture Vi ...
- YoLo 实践(1)
目录 YoLo 实践(1) 目标: 实施方法: Step 0. 测试项目是否可以正常运行 运行效果图 使用VOC数据结构训练模型 Step1: 生成统一格式的标注文件和类别文件 Step2: 加载预训 ...
- VS2015开发环境的搭建
下面我教大家如何搭建VS2015 [环境]我的环境WIN8.1专业版(Ghost) [过程] [1]打开我们的附件vs2015.ent_chs.iso然后我们会进入到这个ISO文件中(windows版 ...
- 阿里云上面部署mysql
0.卸载已有的mysql 系统中可能早已存在mysql数据库,所以在安装之前我们需要将其卸载掉. # rpm -qa|grep -i mysql 该命令将显示已经安装了的mysql软件,之后通过下面的 ...
- LeetCode-Container With Most Water-zz
先上代码. #include <iostream> #include <vector> #include <algorithm> using namespace s ...
- lvm 相关
求教:/home分区和/root分区的关系 lvm扩容试验 [复制链接] lvm快速使用http://imysql.cn/2008_05_05_quick_startup_lvm Linux LVM学 ...
- mongodb 创建auto increment 自增函数
计数器表 > db.counters.insert({_id: "userid",seq: 0} ); > db.counters.find(); { " ...
- AngularJs学习笔记--Understanding the Controller Component
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javasc ...
- 远程登录-出现身份验证错误[可能是由于CredSSP加密Oracle修正]
问题描述 远程桌面登录时,出现身份验证错误,要求的函数不正确,这可能是由于CredSSP加密Oracle修正. 原因,系统更新导致 CVE-2018-0886 的 CredSSP 更新 解决方法1 运 ...
- 我上线的android版app
把自己开发的几个小的app上线了,在自己的博客中推广一下吧: 聊天兔子: 下载地址:http://android.myapp.com/myapp/detail.htm?apkName=com.fuly ...