Square Coins

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

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
 
题意:有17种钱币S[i]=i*i,给一个小于等于300的数,问有多少中组成这个数的方法。
dfs超时,应该是自己写得不好,然后想到母函数,自己写的也超时,非常费解,看了别人的代码,感觉时间上出入很小,感觉是有点卡时间。
对母函数的理解又加深了一点。
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; int S[];
int c1[];
void cal(int n)
{ int c2[n+];
for(int i=; i<=n; i++)
{
c1[i]=;
c2[i]=;
}
for(int i=; i<=; i++)
{
for(int j=; j<=n; j++)
for(int k=; k+j<=n; k+=i*i)
c2[j+k]+=c1[j];
for(int j=; j<=n; j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
//return c1[n];
} int main()
{
int n;
//for(int i=1;i<=17;i++)
// S[i]=i*i;
cal();
while(scanf("%d",&n)!=EOF&&n)
{
printf("%d\n",c1[n]);
}
return ;
}

HDU_1398_母函数的更多相关文章

  1. hdu2082 找单词 (母函数)

    找单词 题意: 中文题,考虑是不是要写个英文题意..(可惜英语水平不够  囧rz)                (题于文末) 知识点: 母函数(生成函数): 生成函数有普通型生成函数和指数型生成函数 ...

  2. hdu1521 排列组合(指数型母函数)

    题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...

  3. Thinkphp的单字母函数整理

    有人不太喜欢TP这种单字母函数,其实这也是TP的一个特色,如果理解了这些函数的作用,不管是背,还是写,都是非常方便的,接下来我们以字母顺序开始.A函数 B函数 C函数 D函数 F函数 L函数 R函数 ...

  4. ThinkPHP单字母函数(快捷方法)使用总结

    在ThinkPHP中有许多使用简便的单字母函数(即快捷方法),可以很方便开发者快速的调用,但是字母函数却不方便记忆,本文将所有的字母函数总结一下,以方便以后查找. 1.U() URL组装 支持不同UR ...

  5. hdu 1398 Square Coins (母函数)

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

  6. [BZOJ3696][FJSC2014]化合物(异或规则下的母函数)

    题目:http://hzwer.com/3708.html 分析: 类似树分治思想,设f[x][i]表示以x为根的子树的所有点中,与x的距离为i的点有多少个,这个可以预处理出来 然后我们考虑每颗子树对 ...

  7. hdu1521 指数型母函数

    排列组合 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. UVa12298 Super Poker II(母函数 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...

  9. HDU4609 3-idiots(母函数 + FFT)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4609 Description King OMeGa catched three men wh ...

随机推荐

  1. ansible ad-hoc 参考

    # 检查主机连接 # ansible test -m ping # 执行远程命令 # ansible test -m command -a 'uptime' # 执行主控端脚本 # ansible t ...

  2. zookeeper监控之taokeeper

    1.taokeeper简介 淘宝的开源监控zookeeper的工具,年久失修! 项目地址: https://github.com/alibaba/taokeeper 监控项: CPU/MEM/LOAD ...

  3. 清北学堂模拟赛d2t5 吃东西(eat)

    题目描述一个神秘的村庄里有4家美食店.这四家店分别有A,B,C,D种不同的美食.LYK想在每一家店都吃其中一种美食.每种美食需要吃的时间可能是不一样的.现在给定第1家店A种不同的美食所需要吃的时间a1 ...

  4. springCloud学习-分布式配置中心(Spring Cloud Config)

    1.简介 Spring Cloud Config :分布式配置中心,方便服务配置文件统一管理,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中.在spring cloud co ...

  5. hdu_1060_Leftmost Digit_201311071827-2

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. cogs 290. [CTSC2000] 丘比特的烦恼

    290. [CTSC2000] 丘比特的烦恼 ★★★   输入文件:cupid.in   输出文件:cupid.out   简单对比时间限制:1 s   内存限制:128 MB 随着社会的不断发展,人 ...

  7. 机器学习10k均值

    下面介绍无监督机器学习算法,与前面分类回归不一样的是,这个不知道目标变量是什么,这个问题解决的是我们从这些样本中,我们能发现什么. 这下面主要讲述了聚类算法,跟数据挖掘中的关联挖掘中的两个主要算法. ...

  8. [E2E] Visual Differing Tests with Puppeteer and PixelMatch

    Take your end to end tests to the next level by comparing your current application's view with an al ...

  9. js+jquery动态设置/添加/删除/获取元素属性的两种方法集锦对照(动态onclick属性设置+动态title设置)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html140 ...

  10. 【Geforce】关于如何在Geforce Experience中登录

    相信不少人无法登录这个该死的Geforce Experience.这里提供几个解决方案: 1.在“服务”中启动运行 NVIDIA NetworkService Container 方式改为手动或者自动 ...