Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数
step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1。临时区 temp初始化 为 0
step 2:遍历后续的n - 1 个 多项式 ,第二重 for j 代 表 的 存 储 结 果 的 多 项 式的次数,k 代表 当前 第 i 的 多项式的次数
通过计算发现两个多项式相乘 其中一个 系数为1和 0 组成,运算时可以初始化系数数组为0 ,然后 由另一个的系数 与之相加即可得到
G(x)=(1+x+x2+x3+x4+.....)(1+x2+x4+x6+x8+......)(1+x3+x6+x9+....)........(1+xn)
#include<bits/stdc++.h>
using namespace std;
#define maxn 234
int ans[maxn],tp[maxn],n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=0; i<=n; i++)
ans[i]=1,tp[i]=0;
for(int i=2; i<=n; i++)
{
for(int j=0; j<=n; j++)
for(int k=0; k+j<=n; k+=i)
tp[j+k]+=ans[j];
for(int j=0; j<=n; j++)
ans[j]=tp[j],tp[j]=0;
}
printf("%d\n",ans[n]);
}
return 0;
}
Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数的更多相关文章
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- Ignatius and the Princess III HDU - 1028
题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...
- 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 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- hdu 1028 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 Ignatius and the Princess III (母函数或者dp,找规律,)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- IE11总是有缓存的问题
F12,里面选择网络,始终从服务器刷新..
- mysql之视图,触发器,事务等。。。
一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...
- linux下安装nginx及初步认识
linux下安装配置nginx nginx:是一个高性能的反向代理服务器正向代理代理的是客户端,反向代理代理的是服务端. 这里以nginx-1.12.2版本为例子 1.首先去官网下载nginx-1.1 ...
- 【python】mongo删除数据
参考:https://stackoverflow.com/questions/23334743/setting-justone-limiter-for-pymongo-remove-throws-ty ...
- PDF文件如何标注,怎么使用PDF标注工具
我们在使用文件的时候需要给文件的部分添加标注,能够更加直观的了解文件,但是有很多小伙伴们对于PDF文件怎么添加标注都不知道,也不知道PDF标注工具要怎么使用,那么下面就跟大家分享一下怎么使用PDF标注 ...
- lisp : set 与setq 函数
在Lisp中,如果我们希望对一个变量赋值,可以使用set函数,用法如下: (set ‘my-value "my string") 上面的代码是对变量my-value进行赋值,值是& ...
- How does exercise keep your brain young?
Exercise may protect the brain from disease and dementia as we age, but the mechanisms behind its be ...
- python 装饰器(1)
# 装饰器,对一个函数打扮 # def foo():# print("foo")# foo# foo()# def test1():# print('-----1-----')# ...
- Git reset与checkout的区别
reset: 将暂存区的文件回撤到工作区,文件内容不会有任何变化 checkout: 将工作区文件恢复到上一次commit时的内容,将会丢失修改了但未加入暂存区的内容
- java解析html的table
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org. ...