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 ...
随机推荐
- Meteor Assets资源
静态服务器资源位于应用程序内的 private 子文件夹.在这个例子中,我们将学习如何从简单的JSON文件中使用数据. 第1步 - 创建文件和文件夹 让我们创建一个 private 文件夹并在这个文件 ...
- [转]JAVA异常
异常 异常就是导致程序中断执行的一段指令流. 在java中, 对于异常在API中也有明确的定义,叫做异常类. Error : JVM的错误, 程序中不进行处理, 交给虚拟机. Exception : ...
- Linux内核project导论——网络:Filter(LSF、BPF、eBPF)
概览 LSF(Linux socket filter)起源于BPF(Berkeley Packet Filter).基础从架构一致.但使用更简单.LSF内部的BPF最早是cBPF(classic).后 ...
- 获取当前时间 YYYY-MM-DD
1.函数封装 /** * 获取当前时间 * 格式YYYY-MM-DD */ Vue.prototype.getNowFormatDate = function() { var date = new D ...
- java克隆对象clone()的使用方法和作用
转自:997.html">http://www.okrs.cn/blog/news/?997.html 内容摘要 若需改动一个对象,同一时候不想改变调用者的对象.就要制作该对象的一个本 ...
- Visual Studio安装空白 和 VS Code打开失败解决方案
微软博文:https://docs.microsoft.com/zh-cn/visualstudio/install/troubleshooting-installation-issues?view= ...
- 为经典版eclipse添加web and JavaEE插件
地址:http://download.eclipse.org/releases/juno. 选择Web,XML,Java EE and OSGI Enterprise Development,之后ne ...
- A + B Problem II(杭电1002)
/*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...
- input from 表单提交 使用 属性 disabled="disabled" 后台接收不到name="username"的值
input from 表单提交 使用 属性 disabled="disabled" 后台接收不到name="username"的值
- IDEA 使用方法快捷键
Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Shift+Click,可以关闭文件Ctrl+[ ...