AcWing 7. 混合背包问题
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std ;
const int N=;
int f[N],g[N],q[N];
int n,m;
int a[N];
int main() {
cin>>n>>m;
for(int i=; i<=n; i++) {
int v,w,s;
cin>>v>>w>>s;
if(s==) { //完全背包
for(int j=v; j<=m; j++)
f[j]=max(f[j],f[j-v]+w);
} else {
if(s==-)//如果是01背包
s=;//换成s就只有1
memcpy(g,f,sizeof f);
for(int j=; j<v; j++) {
int hh=,tt=-;
for(int k=j; k<=m; k+=v) {
if(hh<=tt&&q[hh]<k-s*v)
hh++;
if(hh<=tt)
f[k]=max(f[k],g[q[hh]]+(k-q[hh])/v*w);
while(hh<=tt&&g[q[tt]]-(q[tt]-j)/v*w<=g[k]-(k-j)/v*w)
tt--;
q[++tt]=k;
}
}
}
}
cout<<f[m]<<endl;
return ;
}
AcWing 7. 混合背包问题的更多相关文章
- acwing 7 混合背包
习题地址 https://www.acwing.com/problem/content/description/7/ 题目描述有 N 种物品和一个容量是 V 的背包. 物品一共有三类: 第一类物品只 ...
- HDU 3594 The trouble of Xiaoqian 混合背包问题
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- AcWing 6. 多重背包问题 III
//f[i,j] 所有只从前i块能量石中选,且总体积恰好为j的方案数 #include <iostream> #include <algorithm> #include < ...
- AcWing 9. 分组背包问题
#include <iostream> #include <algorithm> using namespace std; ; int n, m; int v[N][N], w ...
- AcWing 5. 多重背包问题 II
//二进制优化 最后变为01背包 #include <iostream> #include <algorithm> using namespace std; , M = ; i ...
- AcWing 3. 完全背包问题
朴素 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; int v[N],w[N] ...
- AcWing 4. 多重背包问题
朴素 数据范围小 //数据范围小 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; ...
- AcWing 2. 01背包问题
朴素 //朴素二维 #include <iostream> #include <algorithm> using namespace std; ; int n, m; int ...
- acwing 4 多重背包问题 I
多重背包 有 n种物品 一共有 m大小的背包,每种物品的价值 大小 个数 为 s[i],v[i],num[i]; #include<bits/stdc++.h>//cmhao #defin ...
随机推荐
- zabbix-agent TIME_WAIT 过多(转)
一.系统环境 操作系统: Centos 6.4 64bit zabbix-agent 版本: Zabbix agent v2.2.7 (revision 50148) (24 October 2014 ...
- 【题解】 2月19日 厦门双十中学NOIP2014模拟D2 T2 采药人接水果
[问题描述] 采药人虽然 AFO(SU),但他在闲暇的时候还是可以玩一玩接水果(cat)的.但他渐渐发现 cat 好像有点太弱智.于是他不想浪费他的智商,于是决定写一个程序帮他玩. cat 是这样玩的 ...
- SharePoint PowerShell SendEmail
前言 最近碰到这样一个需求,用户需要个简单的定时邮件提醒,就是抓取SharePoint某个列表里的值,然后作为邮件地址/邮件主题/邮件内容发送出去. 自己想了想,既然用户要求每天定时发送,那么肯定是任 ...
- PyCharm专业版激活+破解到期时间2100年
PyCharm专业版激活+破解到期时间2100年 转载文章:https://blog.51cto.com/13696145/2464312?source=dra 到2020年5月激活码: N7UR85 ...
- 在window上安装mysql - MySQL5.7.24 版本
1.下载安装包 下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 点击Download,选择 No thanks, just ...
- sql server 基本操作
1输入如下命令,即可通过SQL Server命令行启动.停止或暂停的服务. SQL Server命令行如下: 启动SQL ServerNET START MSSQLSERVER 暂停SQL Serve ...
- P4735 最大异或和 /【模板】可持久化Trie
//tire的可持久化 //线段树的可持久化——主席树 //可持久化的前提:本身的拓扑结构在操作时不变 //可以存下来数据结构的所有历史版本 //核心思想:只记录每一个版本与前一个版本不一样的地方 / ...
- Bootstrap 手机屏幕自适应的响应式布局开关
head中添加 <meta name="viewport" content="width=device-width, initial-scale=1, shrink ...
- day 8 函数编程_byets
定义 bytes类型是指一堆字节的集合,在python中以b开头的字符串都是bytes类型 b'\xe5\xb0\x8f\xe7\x8c\xbf\xe5\x9c\x88' #b开头的都代表是bytes ...
- jQuery---each方法
each方法 each方法 //each方法 $("li").each(function (index, element) { $(element).css("opaci ...