單調隊列優化多重背包

就是按照 % 體積的余數來分組,每組單調隊列優化。

直接上模板好了。

 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.pswp.cn/news/275603.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275603.shtml
英文地址,請注明出處:http://en.pswp.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…