单调队列优化多重背包

就是按照 % 体积的余数来分组,每组单调队列优化。

直接上模板好了。

 1 #include <bits/stdc++.h>
 2 
 3 typedef long long LL;
 4 const int N = 100010;
 5 
 6 int n, V, cnt[N], cost[N];
 7 LL f[2][N], val[N], p[N], top, head;
 8 
 9 inline void Max(LL &a, const LL &b) {
10     a < b ? a = b : 0;
11     return;
12 }
13 
14 int main() {
15 
16     freopen("bag.in", "r", stdin);
17     freopen("bag.out", "w", stdout);
18 
19     scanf("%d%d", &n, &V);
20     for(int i = 1; i <= n; i++) {
21         scanf("%d%d%lld", &cnt[i], &cost[i], &val[i]);
22     }
23     LL ans = 0;
24     for(int i = 1; i <= n; i++) {
25         for(int j = 0; j < cost[i]; j++) {
26             p[head = top = 1] = 0;
27             for(int g = 1; g * cost[i] + j <= V; g++) {
28                 while(g - p[head] > cnt[i]) head++;
29                 int t = p[head];
30                 Max(f[i & 1][g * cost[i] + j], f[(i - 1) & 1][t * cost[i] + j] + (g - t) * val[i]);
31                 while(top >= head && f[(i - 1) & 1][cost[i] * p[top] + j] + (g - p[top]) * val[i] <= f[(i - 1) & 1][g * cost[i] + j]) {
32                     top--;
33                 }
34                 p[++top] = g;
35             }
36         }
37         for(int j = 0; j <= V; j++) {
38             Max(ans, f[i & 1][j]);
39             f[(i - 1) & 1][j] = f[i & 1][j];
40         }
41     }
42     
43     printf("%lld\n", ans);
44     return 0;
45 }
46 /*
47 5 50
48 1 1 7
49 2 1 4
50 2 4 1
51 3 1 3
52 2 3 8
53 -------------- 42
54 */
AC代码

 

转载于:https://www.cnblogs.com/huyufeifei/p/10531883.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275603.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2021年7月 虾皮、货拉拉、有赞等面经总结

大家好&#xff0c;我是若川&#xff0c;加我微信 ruochuan12 进源码交流群。今天分享一篇7月份新鲜出炉的面经&#xff0c;文章较长&#xff0c;可以收藏再看。学习源码系列、面试、年度总结、JS基础系列。本文来自作者几米阳光 投稿 原文链接&#xff1a;https://juejin.cn/p…

Oracle对表名大小写敏感吗,让Oracle 大小写敏感 表名 字段名 对像名

一、解决方案1、在表名、字段名、对象名上加上双引号&#xff0c;即可实现让oracle大小写区分。2、但是这又引起了另一个问题&#xff1a;在数据库操作中&#xff0c;sql语句中相应的表名、字段名、对象名上一定要加双引号。解决办法是&#xff1a;使用"\"转义。如&a…

谷歌抽屉_Google(最终)会杀死导航抽屉吗?

谷歌抽屉A couple of months ago Google has celebrated with enthusiasm 15 years of Google Maps, one of the most used and appreciated services worldwide from the company.几个月前&#xff0c;Google热情地庆祝Google Maps诞生15周年&#xff0c;这是该公司在全球范围…

MySQL——安装

MySQL——安装 1. 下载源&#xff1a; http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql80-community-release-el7-2.noarch.rpm 该源目前为8.0版本&#xff0c;如果需要最新请退至根目录找。 1wget http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_…

写给初中级前端的高级进阶指南等

大家好&#xff0c;我是若川。话不多说&#xff0c;这一次花了几小时精心为大家挑选了20余篇好文&#xff0c;供大家阅读学习。本文阅读技巧&#xff0c;先粗看标题&#xff0c;感兴趣可以都关注一波&#xff0c;绝对不亏。程序员成长指北考拉妹子&#xff0c;一个有趣的且乐于…

oracle for函数,oracle分区表述的FOR语句(一)

指定一个分区除了使用分区名称外&#xff0c;很多时候还可以使用FOR语句。从11g开始&#xff0c;对分区进行操作的时候&#xff0c;不仅可以使用分区名称&#xff0c;还可以使用FOR语句。在10g中&#xff0c;MERGE RANGE分区的语句如下&#xff1a;SQL> SELECT * FROM V$VER…

axure9控件树 rp_如何在Axure RP 9中创建分段控件

axure9控件树 rpSegmented controls are not very easy to tackle in prototyping. This is especially true when you have more than 2 segments. This article will show you how to create a segmented control with 3 segments in Axure in just 2 simple steps. The tech…

stack

1. 栈数据结构简单介绍 2. 简单实现代码及stl中stack简单使用 3. 代码下载 1. 栈数据结构简单介绍 栈是这样的一种数据结构&#xff0c;遵循“先进后出”的原则。在stack上定义如下的operations&#xff1a; 1. 判空 2. 入栈push 3. 出栈pop&#xff0c;在栈的不同实现版本中&…

MacOS搭建环境

基础环境 从AppStore下载 有道云笔记微信网易云音乐Chrome浏览器postmanChrome插件云笔记剪报基础命令 mac下别名vi ~/.bash_profile 添加 alias llls -alF alias lals -A alias lls -CF 保存后执行(不能有空格) source ~/.bash_profile复制代码开发环境 PhpStorm 从官网下载Ph…

【送书-小姐姐配音】低代码平台的核心价值与优势

大家好&#xff0c;我是若川。记得点上方听小姐姐配音&#xff0c;识别下方二维码加我微信 ruochuan12&#xff0c;明天&#xff08;8月8日&#xff09;晚8点在朋友圈发动态。点赞抽3位小伙伴包邮送《实战低代码》&#xff0c;细则见动态。最近组织了源码共读活动&#xff0c;每…

oracle静默安装集群,静默安装Oracle数据库10g篇

静默安装Oracle数据库10g篇以下是在Linux系统上静默安装Oracle数据库10g的实践过程&#xff0c;主要分为以下两个步骤&#xff1a;Step 1&#xff0e;静默安装Oracle数据库10g软件1. 使用OUI录制响应文件&#xff0c;记录安装过程执行以下命令&#xff0c;然后在OUI中根据提示执…

sketch钢笔工具_设计工具(Sketch,Adobe XD,Figma和InVision Studio)中奇怪的一项功能

sketch钢笔工具When you build a new product that is very similar to the existing products in the market, the designers and product managers tend to do certain features different from others. Sometimes this brings a good change, sometimes worse.当您构建与市场…

modprobe:FATAL: could not load /lib/modules/2.6.35-22-generic/modules.dep No such file or directory

给ubuntu升级到10.10 &#xff0c;开机可能出现错误modprobe:FATAL: could not load /lib/modules/2.6.35-22-generic/modules.dep No such file or directorymodprobe:FATAL: could not load /lib/modules/2.6.35-22-generic/modules.dep No such file or directory解决办法&a…

Python进阶:如何将字符串常量转化为变量?

2019独角兽企业重金招聘Python工程师标准>>> 前几天&#xff0c;我们Python猫交流学习群 里的 M 同学提了个问题。这个问题挺有意思&#xff0c;经初次讨论&#xff0c;我们认为它无解。 然而&#xff0c;我认为它很有价值&#xff0c;应该继续思考怎么解决&#xf…

怎么在matlab中图像中外接矩形,Matlab 最小外接矩形

Matlab 中并没有发现最小外接矩形的代码&#xff0c;为了方便下面提供最小外接矩形的代码&#xff1a;注&#xff1a;这个函数是源于网上找到的代码的改进版&#xff0c;原版不能检测水平线或者垂直线function [rectx,recty,area,perimeter] minboundrect(x,y,metric)% minbou…

尤雨溪开发的 vue-devtools 如何安装,为何打开文件的功能鲜有人知?

1. 前言大家好&#xff0c;我是若川。最近组织了一次源码共读活动。每周读 200 行左右的源码。很多第一次读源码的小伙伴都感觉很有收获&#xff0c;感兴趣可以加我微信 ruochuan12&#xff0c;拉你进群学习。第一周读的是&#xff1a;据说 99% 的人不知道 vue-devtools 还能直…

sketch浮动布局_使用智能布局和调整大小在Sketch中创建更好的可重用符号

sketch浮动布局Sketch is a widely used tool for UI designs. It implemented the Sketch是用于UI设计的广泛使用的工具。 它实施了 atomic design methodology and made the workflow of UI design much more efficient. You can create a Symbol in Sketch and use it ever…

用Sql添加删除字段,判断字段是否存在的方法

增加字段alter table docdsp add dspcode char(200)删除字段ALTER TABLE table_NAME DROP COLUMN column_NAME修改字段类型ALTER TABLE table_name ALTER COLUMN column_name new_data_type改名sp_rename更改当前数据库中用户创建对象&#xff08;如表、列或用户定义数据类型…

小姐姐笔记:我是如何学习简单源码拓展视野的

大家好&#xff0c;我是若川。这是我上周组织的源码共读纪年小姐姐的笔记&#xff0c;写得很好。所以分享给大家。欢迎加我微信 ruochuan12&#xff0c;进源码共读群。其他更多人的笔记可以阅读原文查看。川哥的源码解读文章&#xff1a;据说 99% 的人不知道 vue-devtools 还能…

php表决器代码,三人表决器:VHDL源代码

描述--三人表决器(三种不同的描述方式) vhdl-- Three-input Majority Voter-- The entity declaration is followed by three alternative architectures which achieve the same functionality in different ways.ENTITY maj ISPORT(a,b,c : IN BIT; m : OUT BIT);END maj;--D…