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 ...
随机推荐
- webstorm启动后右下角总有进程在扫描
启动webstorm后,右下角有一个扫描的任务总在执行,其他操作很卡. 搜索后找到一个办法:在node-modules右键,选择Mark Directory As选择exclude 具体原因没找到.
- Ubuntu / Raspberry 下切换GCC版本
目前Ubuntu 自带的GCC版本为4.6,遗憾的是在实际使用时,反而版本越高越好问题越多,所以,一旦遇到编译问题时最好先检查你下载的工程里的readme,默认的编译器版本是否为当前的安装版本,如果不 ...
- EF多实体对应单表
1.EF多实体对应单表 适用场景:单数据库表,表数据有较长用字段,有不常用或者大数据字段. 2.建表语句 CREATE TABLE [Chapter2].[Photograph]( ,) primar ...
- scrum心得和团队作业
一.学习scrum心得 敏捷的介绍 最近上课我们了解到了敏捷,很多人开始谈论敏捷开发.研究敏捷开发,那么究竟什么才是敏捷开发呢? 简单的说,敏捷开发是一种以人为核心.迭代.循序渐进的开发方法.在敏捷开 ...
- arm汇编学习(三)
一.ndk编译android上运行的c程序 新建个hello目录,底下要有jni目录,下面就是Android.mk文件 1.Android.mk文件内容如下: LOCAL_PATH:= $(call ...
- 如何在 Maven 工程中引入其他jar包 并生效?(以 Netty 为例)
1.到 Maven 官网 查找 相关 框架 https://mvnrepository.com/artifact/io.netty/netty-all/4.1.32.Final 2.把相关 Xml体 ...
- skype for business server 2015 报错“不可用:试图检查架构状态时发生故障,请确保能够访问Active Direcotry”
报错“不可用:试图检查架构状态时发生故障,请确保能够访问Active Direcotry” 遇到错误后就上网查询了下,有的人说用下面方法解决了 用域的administrator 登入就可以了(之前是用 ...
- 你所不知道的C和C++运行库 标签: vc 2017-05-26 10:33 41人阅读 评论(0) 收藏
在使用vs2013调用vc2005编译出的dll时出现错误,遂将源程序用vs2013编译出dll,再用vs2013调用错误消失,不解.寻找原因时有人说"VC库版本不一样",故查找C ...
- Fatal error: Call to undefined function fnmatch() 解决
我的PHP版本是5.6.30,linux 是CentOS 6.6,nginx,也不知啥问题,看了官方: https://secure.php.net/manual/en/function.fnmatc ...
- TaskScheduler内幕天机解密:Spark shell案例运行日志详解、TaskScheduler和SchedulerBackend、FIFO与FAIR、Task运行时本地性算法详解等
本课主题 通过 Spark-shell 窥探程序运行时的状况 TaskScheduler 与 SchedulerBackend 之间的关系 FIFO 与 FAIR 两种调度模式彻底解密 Task 数据 ...