当前位置:网站首页>Move bricks (greedy perturbation + 01 backpack)
Move bricks (greedy perturbation + 01 backpack)
2022-07-26 01:48:00 【to cling】
The 13th National Blue Bridge Cup
Problem
Yes n n n Items , The first i i i The volume and value of each item are v i , w i v_i, w_i vi,wi . Now from here n Take some items out of the items , Line up , Make the value of each item greater than or equal to the item in front of it Total volume . Find the maximum value of the items taken out .
Solution
Greedy perturbation is a little metaphysical .. You can do it first 《 King's game 》 The subject , Get to know “ Perturbation ” The process of analyzing a topic .
First , Considering how to ensure that the total volume of an item in front of it is less than the value of the item , There will be no clue . However , If it's difficult, it's the opposite .
therefore , You can deal with the items in front first , Then deal with the following items first .After that, choose items .
After thinking, you can find , The selection order of items can affect the result , direct 01 The backpack seems inappropriate .( I don't quite understand why sorting items will affect 01 It's a backpack dp The process , I hope some big guys can explain it in the comment area , thank [doge])How to sort : Sort according to the sum of the value and volume of the goods from small to large .
The proof method is : Perturbation method .
The following is the proof processUnder the condition that the conditions in the topic are met :
Suppose... Of these items taken out i i i Items and The first i + 1 i + 1 i+1 The volume and value of each item are ( v i , w i v_i, w_i vi,wi)( v i + 1 , w i + 1 v_{i + 1}, w_{i + 1} vi+1,wi+1)
Set before i − 1 i - 1 i−1 The total volume of this article is s u m sum sumAccording to the conditions in the title : s u m + v i ≤ w i + 1 sum + v_i \leq w_{i + 1} sum+vi≤wi+1
In exchange for i i i Items and i + 1 i + 1 i+1 Location of items : Other items and article i + 1 i + 1 i+1 Items still meet the conditions in the title .( Simple thinking and analysis shows )
And the first i Whether the item meets the conditions , There is a relationship :
If after the exchange i i i Items Do not meet the conditions in the topic , Then the total value decreases , That is, the result becomes worse . So there are : s u m + v i + 1 > w i sum + v_{i + 1} > w_i sum+vi+1>wi
Two inequalities can be combined to obtain : w i − v i + 1 < s u m ≤ w i + 1 − v i w_i - v_{i + 1} < sum \leq w_{i + 1} - v_i wi−vi+1<sum≤wi+1−vi
namely w i − v i + 1 < w i + 1 − v i w_i - v_{i + 1} < w_{i + 1} - v_i wi−vi+1<wi+1−vi, It is reduced to : w i + v i < w i + 1 + v i + 1 w_i + v_i < w_{i + 1} + v_{i + 1} wi+vi<wi+1+vi+1It can be seen from the above analysis : When the first i i i The sum of the value and volume of an article Less than The first i + 1 i + 1 i+1 The sum of the value and volume of an item , The result after exchange Variation .
in other words : If all the items were sorted from small to large according to the sum of value and volume ,
After scrambling the order , There are more reverse pairs , The worse the result .
Code
#define ft first
#define sd second
#define pii pair<int, int>
const int N = 2e3 + 5;
pii s[N];
int f[20100];// Maximum volume :20 + 20000
int main()
{
IOS;
int n; cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i].ft >> s[i].sd;//first Is the volume ,second For value
sort(s + 1, s + n + 1, [&](pii &a, pii &b) {
return a.ft + a.sd < b.ft + b.sd;
});
//dp[i][v]: front i Items , The total volume is v when , The maximum value that can be accommodated
// Select the first i Item , Before request i - 1 The total volume of this article is less than i The value of items
// Select the first i When it comes to items , Maximum volume = s[i].ft + s[i].sd ( front i - 1 The total volume of the item plus i The volume of items v[i])
// Select the first i When it comes to items , Minimum volume = s[i].ft ( There are no objects in front ,i Is the first item )
for (int i = 1; i <= n; i++)
for (int v = s[i].ft + s[i].sd; v >= s[i].ft; v--)
f[v] = max(f[v], f[v - s[i].ft] + s[i].sd);
cout << *max_element(f, f + 20021) << endl;
return 0;
}
Over
边栏推荐
- Spark-SQL中根据年月日显示周几用date_format(date,‘u‘)
- [untitled]
- The best way to practice Animation: cover transition
- proto转换Dart | 项目使用Protobuf | flutter 使用grpc
- Mysql_ Note1
- "Weilai Cup" 2022 Niuke summer multi school training camp 2 h.[take the elevator] maintenance section
- Travel (split points and layers)
- 怎么使用宝塔面板把node全栈项目部署到服务器上
- “蔚来杯“2022牛客暑期多校训练营2 I.[let fat tension] 矩阵乘法 J.[Link with Arithmetic Progression]线性回归
- 推荐⼀款超好⽤的UI⾃动化⼯具: UiAutomator2!
猜你喜欢

Prime Ring Problem

SOC first project hello_ world

There is no setter method in grpc list under flutter. How to use related attributes

Google gson usage details

C语言中的整型数据类型(你真的了解吗)

Two stage submission and three stage submission

Leetcode537. Complex multiplication (yes, solved)

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

Go operation excel library excel use

What should I do when my blog is attacked by hackers?
随机推荐
"Weilai Cup" 2022 Niuke summer multi school training camp 2 i.[let fat tension] matrix multiplication j.[link with arithmetic progression] linear regression
Software group verification
The sales volume has won the championship repeatedly. Is the secret of Wuling's success only low price?
leetcode/只出现一次的数字
[Unity] 二维洞穴地图随机生成
给RestTemplate添加拦截器记录请求响应,还需解决流只读一次的问题
"Weilai Cup" 2022 Niuke summer multi school training camp 2 k.[link with bracket sequence i] bracket sequence DP
【Verilog数字系统设计(夏宇闻)3-----Verilog语法的基本概念1】
Typora expiration solution, what if typora can't open
"Weilai Cup" 2022 Niuke summer multi school training camp 2 g.[link with monotonic subsequence] block structure
Excuse me, sir. Oracle to PG CDC Oracle, the upper case of the field is the same as that of PG
“蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
FFT用于估计插值后的图像重采样因子
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
Zombie's treasure test (enumeration)
proto转换Dart | 项目使用Protobuf | flutter 使用grpc
Prime Ring Problem
在Anaconda 中安装和使用R
【Verilog数字系统设计(夏宇闻)4-----Verilog语法的基本概念2】
CPU的三种模式