母函数介绍见另一篇随笔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. 函数 xdes_get_descriptor_with_space_hdr

    获得区描述符 xdes entry 的offset /********************************************************************//** ...

  2. sql Server 的基本函数

    --聚合函数 use pubs go select avg(distinct搜索 price) --算平均数 from titles where type='business' go use pubs ...

  3. SDOI 2010 and SXOI 2014 地精部落 (递推)

    用E[i,j]表示共有i个数字,以1..j开头且一开始下降的方案数的总和.则我们有: E[i,j]:=E[I,J-1]+E[i-1,i-j] 我们先来证明上升与下降的方案是一一对应的. 事实上,若有a ...

  4. EF4.0和EF5.0增删改查写法区别

    1 public T AddEntity(T entity) 2 { 3 //EF4.0的写法 4 添加实体 5 //db.CreateObjectSet<T>().AddObject(e ...

  5. wdcp系统升级mysql5.7.11

    1.下载解压 下载地址为:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ...

  6. 从投影的角度理解pca:向量,投影,基,内积,坐标,维数,分散程度,方差,协方差矩阵,对角化,特征值分解,主成分分析PCA

    参考:http://blog.csdn.net/songzitea/article/details/18219237

  7. ffmpeg windows 雪花声解决方法

    替换所有文件里的<math.h>为<mathimf.h>即可. 我用ffmpeg-0.6.3版测试时,好像mathimf.h文件和其他文件有冲突,需要修改源码. 和qdm2.c ...

  8. linux lnmp编译安装

    关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled ...

  9. Mysql读写分离(mysql-proxy)

    MySQL-Proxy是一个处于你的client端和MySQL server端之间的简单程序,它可以监测.分析或改变它们的通信.它使用灵活,没有限制,常见的用途包括:负载平衡,故障.查询分析,查询过滤 ...

  10. python 去掉\n\t多余空格

    >>> import re >>> sss = "SELECT a.id,\n       a.customer_id as user_id,\n     ...