母函数介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数)

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MAXN 400005
#define INF 2000000007
#define mem(a) memset(a,0,sizeof(a)) int c1[],c2[]; int main()
{
int n;
while(~scanf("%d",&n) && n!= )
{
int i;
for(i = ;i<=n;i++)
{
c1[i] = ;
c2[i] = ;
}
for(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] = ;
}
}
printf("%d\n",c1[n]);
}
return ;
}

另外我也写了一个其他方法,可以看看

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MAXN 400005
#define INF 2000000007
#define mem(a) memset(a,0,sizeof(a)) int ans(int n,int k)
{
if(k == )return ;
int x = n/(k*k);
int num=;
for(int i = ;i<= x; i++)
{
num += ans(n-i*k*k, k-);
}
return num;
} int main()
{
int n;
while(~scanf("%d",&n) && n != )
{
int i,key;
for(i =;i<=;i++)
{
if(i*i > n){
key = i-;
break;
}
}
printf("%d\n",ans(n,key));
}
return ;
}

HDU1398Square Coins(母函数)的更多相关文章

  1. 动态规划:HDU-1398-Square Coins(母函数模板)

    解题心得: 1.其实此题有两种做法,动态规划,母函数.个人更喜欢使用动态规划来做,也可以直接套母函数的模板 Square Coins Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU-1398-Square Coins(母函数)

    链接: https://vjudge.net/problem/HDU-1398 题意: People in Silverland use square coins. Not only they hav ...

  3. hdu 1398 Square Coins (母函数)

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

  4. HDOJ 1398 Square Coins 母函数

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

  5. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  6. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  7. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

随机推荐

  1. 带你认识HTML5中的WebSocket

    这篇文章主要介绍了带你认识HTML5中的WebSocket,本文讲解了HTML5 中的 WebSocket API 是个什么东东.HTML5 中的 WebSocket API 的用法.带Socket. ...

  2. iOS开发:mac使用svn管理项目

    记录mac下常用的svn命令: 1.检出项目: svn checkout .../svn/projectName --username=xxx --password=xxx //将ip换成svn服务器 ...

  3. IIS Server is too busy 解决方法(IIS6)

    Server is too busy意思是服务器繁忙,资源不够用 为什么会出现这个问题呢? 因为服务器的配置不同,所能承受的压力不同. 而服务器默认对链接数,线程数等有设置,但这个设置太小,基本不够用 ...

  4. ASP.NET缓存OutputCache和Response.Cache之C#后台设置

    一.ASPX页面缓存页面缓存的使用方法非常的简单,只需要在aspx页的顶部加一句声明<%@ OutputCache Duration="60" VaryByParam=&qu ...

  5. 实现一个简单的FTP服务器(十四)

    此为一个网络编程的一个系列,后续会把内容补上...

  6. 完整cocos2d-x编译Andriod应用过程

    作者:何卫 转载请注明,原文链接:http://www.cnblogs.com/hewei2012/p/3366969.html 其他平台移植:http://cocos2d.cocoachina.co ...

  7. $http POST 转字符串

  8. 数据库语言(一):SQL语法实例整理

    数据库系统以一些语句作为输入,并返回一些输出,例如sql查询总是返回一张表,我们定义:具有相同格式的记录的集合是一张表. 考虑大学数据库系统: SQL中的数据类型: char(n) 字符串长度为n   ...

  9. 《C++ Primer 4th》读书笔记 第8章-标准IO库

    原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936457.html

  10. DevExpress z

    1.TextEditor(barEditItem)取文本 string editValue = barEditItem1.EditValue.ToString();    //错误,返回null st ...