51nod 1086 背包问题 V2 多重背包
来源:互联网 发布:qq三国张飞打技能数据 编辑:程序博客网 时间:2024/05/16 04:53
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1086
题意:有N种物品,每种物品的数量为C1,C2......Cn。从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi为整数)。求背包能够容纳的最大价值。
标准的多重背包
#include <iostream>#include<bits/stdc++.h>using namespace std;int d[55000],n,m;void zeroonepack(int w,int p){ for(int i=m;i>=w;i--) if(d[i]<d[i-w]+p) d[i]=d[i-w]+p;}void completepack(int w,int p){ for(int i=w;i<=m;i++) if(d[i]<d[i-w]+p) d[i]=d[i-w]+p;}void multipack(int w,int p,int c){ if(w*c>=m) completepack(w,p); else { int k=1; while(k<c) { zeroonepack(k*w,k*p); c-=k; k*=2; } zeroonepack(c*w,c*p); }}int main(){ while(~scanf("%d%d",&n,&m)) { memset(d,0,sizeof(d)); for(int i=0;i<n;i++) { int w,p,c; scanf("%d%d%d",&w,&p,&c); multipack(w,p,c); } cout<<d[m]<<endl; }}
0 0
- 51nod 1086 背包问题 V2(多重背包问题)
- 51nod oj 1086 背包问题 V2 【多重背包问题】
- 51nod 1086 背包问题 V2 (多重背包问题)
- 51Nod 1086背包问题V2(多重背包)
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1086 背包问题 V2(多重背包)
- 51nod 1086 背包问题V2(巧妙拆分多重背包)
- 51nod 1086 背包问题 V2 多重背包
- 51nod 1086 背包问题v2 多重背包
- 51nod 1086 背包问题 V2(多重背包)
- 51Nod 1086 背包问题 V2(多重背包)
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1086 背包问题 V2 (多重背包)
- 【多重背包】51nod 1086 背包问题 V2
- 51Nod-背包问题V2(多重背包+二进制优化)
- 51nod-1086 背包问题(多重背包)
- 【51Nod 1086】背包问题 V2
- 51 Nod 1086 背包问题 V2
- 浅谈一个概率性问题
- DDMS的功能
- Linux文件编辑命令详细整理
- Linux常用命令
- NYOJ 心急的C小加
- 51nod 1086 背包问题 V2 多重背包
- USB键盘数据格式以及按键键值
- Gx平台 bin工具
- mac下的辅助工具
- android 中怎么控制EditText只能输入数字和字母?
- 斯坦福大学机器学习笔记(1)
- is not on any development teams in Xcode7.2 问题解决
- grass gis 的求buffer最基本内容
- jsonp的原理