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 ...
随机推荐
- SharePoint中取得ACL和组中用户数量
SharePoint中取得ACL和组中用户数量 1. 取得ACL的数量: select COUNT(ra.PrincipalId) as [Count],p.ScopeUrl from [WSS_C ...
- Java和C++里面的重写/隐藏/覆盖
首先,无关重载. 注:重载是同一个类的各个函数之间的.重写是父类子类之间的.Overload和Overwrite(也叫Override)的区别. 注意:Java里面区分重写(Override/Over ...
- [React] Extend styles with styled-components in React
In this lesson, you will learn how to extend styles from one styled-component to another in a React ...
- web编程非常实用的在线工具大全
目前,不管是前端开发人员还是个人站长,经常需要一些代码处理类的工具,比如:代码对比.代码格式化.图标制作等.有时就是一时急用可电脑上又没有安装相关的软件,这里为大家收集了一些我们经常会用到的在线工具. ...
- 嵌入式开发之davinci--- 8127 中camer 和 capture link 的区别
(1)camera link (2)capture link (3)两者区别 (1)camera link 走的是isp iss link采集的得到的数据,适用于ipnc 框架 (2)capture ...
- 小贝_mysql数据库备份与恢复
mysql数据库备份与恢复 简要: 一.数据库备份 二.数据库恢复 一.数据库备份 1.备份简单说明 : 系统执行中,增量备份与总体备份 例: 每周日总体备份一次,周一到周 ...
- set 去重 会 破坏 原有list 的元素相对位置
feature_reduce_l = [i if re.search('\d', i) is None else i[0:re.search('\d', i).endpos - 1] for i in ...
- mongodb05---游标
游标cursor: 通俗的说,游标不是查询结果,而是查询的返回资源,或者接口. 通过这个接口,你可以逐条读取.就像php中的fopen打开文件,得到一个资源一样, 通过资源,可以一行一行的读文件. v ...
- next数组求最小循环节
1.kmp产生的next数组: 最小循环节(长度)=len-next[len]; 证明: ----------------------- ----------------------- k m ...
- Mac 下设置Android 环境变量 NDK
1. 启动终端Terminal 2. 进入当前用户的home目录 输入cd ~ 3. 创建.bash_profile 输入touch .bash_profile4. 编辑.bash_profil ...