01背包+完全背包+多重背包模板
来源:互联网 发布:windows一键还原软件 编辑:程序博客网 时间:2024/05/21 16:22
n种物品,容量为v,第i件费用为c[i],价值为w[i]
1.01背包
方程:
f[i][v]=max{f[i-1][v],f[i-1][v-c[i]]+w[i]}
模板:
- void zeropack(int cost,int weight)
- {
- for(int i=v;i>=cost;i--)
- dp[i]=max(dp[i-cost]+weight,dp[i]);
- }
- for(int i=1;i<=n;i++)
- zeropack(c[i],w[i]);
2.完全背包
f[i][v]=max{f[i-1][v-k*c[i]]+k*w[i]|0<=k*c[i]<=v}
- void completepack(int cost,int weight)
- {
- for(int i=cost;i<=V;i++)
- dp[i]=max(dp[i-cost]+weight,dp[i]);
- }
3.多重背包
f[i][v]=max{f[i-1][v-k*c[i]]+k*w[i]|0<=k<=n[i]}
num 为限制几个
- void multipack(int cost,int weight,int num)
- {
- if(num*cost>=V)
- {
- completepack(cost,weight);
- return;
- }
- int k=1;
- while(k<num)
- {
- zeropack(k*cost,k*weight);
- num-=k;
- k*=2;
- }
- zeropack(cost*num,weight*num);
- }
0 0
- 01背包、完全背包、多重背包模板
- 模板-01背包-完全背包-多重背包
- 01背包、完全背包、多重背包模板
- 01背包+完全背包+多重背包模板
- 01背包 完全背包 多重背包模板
- 背包模板(01背包,完全背包,多重背包)
- 背包问题模板(01背包,完全背包,多重背包)
- 完全背包多重背包模板
- 01背包模板、完全背包 and 多重背包(模板)
- 01背包模板、完全背包 and 多重背包(模板)
- 01 完全 多重 背包模板
- 01背包,完全背包,多重背包 ,模板代码
- 01背包、完全背包、多重背包模板代码
- dp 01背包,完全背包,多重背包 模板
- 动态规划之01背包,完全背包,多重背包模板
- hdu 2844 多重背包模板题 01背包、完全背包、多重背包模板
- 01背包,完全背包, 多重背包
- 01背包,完全背包,多重背包
- 文件句柄(file handles) & 文件描述符(file descriptors)
- Vue问题记录
- 如何在github上传自己的项目
- 查看storm运行日志
- spark入门详解
- 01背包+完全背包+多重背包模板
- 【转载】终于解决这个难题了:安装mysql server5.5 到start service未响应
- GBDT(MART) 迭代决策树入门教程 | 简介
- 技术的热门度曲线
- [容斥原理 DP] BZOJ 4767 两双手
- JavaScript function 参数对象arguments (基础)
- 3. Longest Substring Without Repeating Characters
- windows重置网络解决浏览器无法访问
- ros 初学记录(1)安装与创建工作空间