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. 【codeforces 767C】Garland

    [题目链接]:http://codeforces.com/contest/767/problem/C [题意] 一棵树; 树上的每个节点都有一个权值; 让你把一棵树切掉两条边; 然后把这棵树分成了3个 ...

  2. Android学习总结(5)——9个非常有用的Andorid 程序片段

    一,获取系统版本号: PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0); int ...

  3. memcached集群

    借鉴:http://www.cnblogs.com/happyday56/p/3461113.html 首先说明下memcached存在如下问题 本身没有内置分布式功能,无法实现使用多台Memcach ...

  4. USB设备驱动之设备初始化(设备枚举)

    USB设备从接入HUB到正常工作之前.都属于设备枚举阶段.所谓设备枚举.就是让host控制器认识USB设备,并为其准备资源.建立好主机与设备间的数据传递机制. 该阶段的工作,是USB通信协议规定的,所 ...

  5. tiny4412移植opencv2.4.7手记

    在买了新的4412板子后.打算趁着刚成功在6410上移植过的经验,速度解决下.不想出现了各种问题.小结下: 1.关于opencv的移植: tiny4412的linux3.5上,须要把opencv的li ...

  6. luogu1373 小a和uim之大逃离

    题目大意 地面上出现了一个n*m的巨幅矩阵,矩阵的每个格子上有一坨0~k不等量的魔液.怪物各给了小a和uim一个魔瓶,说道,你们可以从矩阵的任一个格子开始,每次向右或向下走一步,从任一个格子结束.开始 ...

  7. inux内核模块编程入门

    linux内核模块编程入门 2013-07-06 23:59:54 分类: LINUX 原文地址:linux内核模块编程入门 作者:s270768095 模块编程属于内核编程,因此,除了对内核相关知识 ...

  8. stack 栈

    其实今天我们主要讲的是搜索,但是留作业不知道怎么就突然全变成栈了. 其实栈和队列没什么区别,只是一个先进先出,一个先进后出.基本操作也是一样的. 栈(stack)又名堆栈,它是一种运算受限的线性表.其 ...

  9. B5090 组题 二分答案

    bzoj有毒,看不了自己哪错了...根本没法debug. 我到现在还是不知道自己代码为什么会T,二分次数也加限制了,但是还是T...救命啊!!! 题干: Description 著名出题人小Q的备忘录 ...

  10. uoj#149

    dp 没想出来 最先开始想 dp[i][j][k]表示s匹配到i,t匹配到j,当前分了k段的方案数 s[i]==t[j] dp[i][j][k]+=dp[i-1][j-1][k-1] s[i]==t[ ...