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 ...
随机推荐
- CRLF与LF解析
window和mac的同学合作开发项目,会出现git提交/拉取时换行符不一致导致,提示 "the text is identical, but the files do not match, ...
- jQuery阻止向上冒泡事件
//阻止起泡取消下面的注释 e.stopPropagation(); //或者使用这种方式 //return false; }); $('.three').click(function(e){ ale ...
- Android输入法架构学习总结
此文为本人学习输入法之后所做的一个总结报告.与大家分享. 安卓输入法框架(Input Method Framework)IMF 一.输入法框架简介 自Android平台1.5版本以后,Google开放 ...
- Common in Hardware & Software
A lot of common in Hardware programming & Software Programming
- 在URL里传入数组到HTML 里。
需求 静态页面根据URL输入,动态显示图表满足如下两个条件. 1. 隐藏指定的行 2. 设定初始显示的Check box 需要的部分被打勾 实现 1. 创建一个静态的页面, <table id= ...
- C#开发小技巧
001.判断一个Form是否已关闭并释放,需要从引用和对象两方面来判断,判断引用是否为null:mainfm==null判断引用的对象是否已释放:mainfm.IsDisposedMainFormma ...
- QT5.3 杂记
Qt5下,QWidget系列从QtGui中被剥离出去,成为单独的QtWidget模块.随着Qt Quick2的引入,QtDeclarative也逐渐和QWidget系列也脱离关系. 最终:在Qt5下的 ...
- PHP 调用web service接口(.net开发的接口)
实例代码1: try { $this->soapClientObj = new SoapClient(self::URL . '?wsdl', array('connection_timeout ...
- tcp.h
/* * Copyright (c) 1991-1997 Regents of the University of California. * All rights reserved. * * Red ...
- IIS 7 启用 gzip 静态压缩 压缩js和css文件
搞了很久,不如nginx好弄,不知道怎么修改压缩比,也不知道怎么压缩的规则是啥(管理器上没有写),不过反正出来了,一个js文件900多K变成了100多K 1.在web.config文件里面加上: &l ...