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. Jquery书写ajax

    根据API学习本章 Jquery书写ajax 使用ajax发送表单到servlet,发送时显示等待图片,servlet处理完返回信息,在页面显示返回信息,并且隐藏等待图片 <%@ page la ...

  2. wmpnetwk.exe怎么禁启动

    Win7控制面板--管理工具--服务,找到并选中"Windows Media Player Network Sharing Service"服务,右键点"属性" ...

  3. Spell checker POJ 1035 字符串

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 De ...

  4. trigger dependencies

    有时候,会想知道某个表是不是会有一些trigger去更新它. 但是一般更新语句是写在trigger 内部,所以我不确定 dba_dependencies这个视图能不能存储这种依赖关系. 做个试验: 创 ...

  5. iOS: 将OC的NSMutableArray转为Swift的Array

    一句话: YourSwiftObject convertedArray = your_MutableArray as NSArray as [YourSwiftObject]

  6. xtrabackup 2.3.3编译安装

    ***************************************************************** 安装 ******************************* ...

  7. windows下solr7.9+tomcat7环境搭建

    1.下载solr.tomcat(能够不用下载.由于solr有jetty支持) 2.solr部署到tomcat上    首先,把解压包下的solr-4.9.0\example\solr-webapp中的 ...

  8. javascript 使用方式

    第一种:内嵌在html节点中 <html> <body> <input type="button" onclick="document.bo ...

  9. jQuery - 点击图片加边框

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...