Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028
整数划分问题
假的dp(复杂度不对)
#include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(ans[x][y]!=-) return ans[x][y];
if(y==) return ans[x][y]=;
if(x<y) return ans[x][y]=;
ans[x][y]=;
LL i;
for(i=;i<=y;i++)
ans[x][y]+=get(x-y,i);
return ans[x][y];
}
int main()
{
memset(ans,-,sizeof(ans));
ans[][]=;
while(scanf("%lld",&n)==)
{
anss=;
for(int i=;i<=n;i++) anss+=get(n,i);
printf("%lld\n",anss);
}
return ;
}
一般的dp
ans[i][j]表示把i拆成最大j的数的方案数。要么分配一个j(剩下ans[i-j][j]),要么一个也不分配(剩下ans[i][j-1])。
#include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(ans[x][y]!=) return ans[x][y];
if(y==) return ;
if(x<y) return ans[x][y]=get(x,x);
return ans[x][y]=get(x-y,y)+get(x,y-);
}
int main()
{
ans[][]=;
while(scanf("%lld",&n)==)
printf("%lld\n",get(n,n));
return ;
}
甚至可以写成这样
#include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(x<) return ;
if(ans[x][y]!=) return ans[x][y];
if(y==) return ;
return ans[x][y]=get(x-y,y)+get(x,y-);
}
int main()
{
ans[][]=;
while(scanf("%lld",&n)==)
printf("%lld\n",get(n,n));
return ;
}
母函数做法

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n;
LL ans[][];//ans[i][j]存的是到第i个多项式为止指数为j的项数
int main()
{
LL i,j,k;
while(scanf("%lld",&n)==)
{
memset(ans,,sizeof(ans));
ans[][]=;
for(i=;i<=n;i++)
for(j=;j<=n;j+=i)
for(k=;k<=n-j;k++)
ans[i][k+j]+=ans[i-][k];
printf("%lld\n",ans[n][n]);
}
return ;
}
Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数的更多相关文章
- Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数
HDU - 1028 step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1.临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 , ...
- Ignatius and the Princess III HDU - 1028
题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...
- HDU 1028 整数拆分问题 Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 整数拆分 HDU 2082 找单词 母函数
生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn 称为序 ...
- hdu,1028,整数拆分的理解
#include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...
- HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- SAS学习笔记 - R的数据操作
1.对象 1.1 对象及其内在属性 R中的处理数据就是对象,每个对象可以包含多个元素.对象有两个内在属性:类型和长度.类型是对象元素的基本种类,共四种:数值型,字符型,复数型和逻辑型.对象的类型和长度 ...
- Excel小tips - 如何实现多列成绩统一排名
本文参考:http://mp.weixin.qq.com/s/XR49hyG9Cods7rOcsM-tRg 如果有以下数据文件,需要进行成绩排名. 第一步:先在成绩列后边添加一列,用来显示名次.如下: ...
- java的计时:毫秒、纳秒
System.currentTimeMillis()获取毫秒值,但是其精度依赖操作系统 想实现较为精确的毫秒,可以采用 System.nanoTime()/1000000L System.nanoTi ...
- Linux面试题完整修订附加答案
册一: 1.Linux挂载Winodws共享文件夹 第一步:先在Windows上创建一个共享目录 Windows系统IP是172.16.18.56;共享文件夹:E:\test ...
- grails的criteria和hql查询
grails在查询方面也保留了hibernate的hql和criteria查询功能.hql自然不必多说基本不会有什么变化,grails的criteria查询在hibernate上面做了微调使用起来更加 ...
- 报错** is not accessible due to restriction on required library
报错: Description Resource Path Location TypeAccess restriction: The type Map<String,Object> is ...
- android 自己定义水平和圆形progressbar 仅仅定义一些style就能够
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- CodeForces 404 Marathon ( 浮点数取模 -- 模拟 )
B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 抓包工具Fiddler使用宝典之捕获手机报文
Fiddler 是通过代理来实现数据捕获的.对 Android 手机来说,也是通过将网络连接的代理指向 PC 机的 Fiddler port.来实现数据包的拦截. 以下,我以我的一次实践为例,向大家介 ...
- showModalDialog参数问题
showModalDialog传递参数: 1.参数拼接放在url中,参数过长或带特殊字符时,容易出现问题. 2.参数放在showModalDialog属性里 <script type=" ...