当前位置:网站首页>[CF559E]Gerald and Path
[CF559E]Gerald and Path
2022-07-01 18:17:00 【OneInDark】
subject
Ideas
generally speaking , We will sort the intervals . Because the interval is essentially Two dimensional partial order Relationship , Sort by endpoint It can make a certain dimension orderly , amount to Dimension reduction .
In this question , The interval is not very fixed . But there are two possible ranges , a i a_i ai Is a common endpoint ; So, in accordance with the a i a_i ai Sorting is natural .
Next, consider d p \tt dp dp Transfer . For example, the current choice [ a i − l i , a i ] [a_i-l_i,a_i] [ai−li,ai], We need to find out its new coverage . however , In this large section , You may have chosen several short paragraphs , It is impossible to record all . What do I do ?
One idea is , Ignore the details . Don't use useless information d p \tt dp dp Status plug . The useful interval may be [ s i , t i ] ( s i < a i − l i < t i ) [s_i,t_i]\;(s_i<a_i-l_i<t_i) [si,ti](si<ai−li<ti) and [ s i , t i ] ( s i < a i < t i ) [s_i,t_i]\;(s_i<a_i<t_i) [si,ti](si<ai<ti), That is, override prefix or suffix .
So let's enumerate an interval p p p, It covers a prefix , The rest of the interval cannot cover its right . p p p It may be left , At this time, the only interval not to be ignored is p p p The previous interval ; p p p Maybe right , The interval that is not ignored is [ 1 , i ) [1,i) [1,i) The range of , This i i i And p p p It doesn't matter. .
So let's not stick to one dimension d p \tt dp dp, remember f ( p , i ) f(p,i) f(p,i) To consider only [ 1 , i ] [1,i] [1,i] Section 、 p p p Select the right section 、 Other sections do not cover p p p To the right , Maximum coverage distance and . Transfer or use the same method , Enumerate the intervals that cover prefixes j j j, from f ( j , p − 1 ) f(j,p{\rm-}1) f(j,p−1) Turn around .
g ( p ) g(p) g(p) To consider only [ 1 , p ] [1,p] [1,p] Section 、 p p p Choose left in the interval 、 Other sections do not cover p p p To the right , Maximum coverage distance and . By contrast , Its transfer is easier , Therefore, it is omitted here .
Time complexity O ( n 3 ) \mathcal O(n^3) O(n3) . The code implementation is relatively smooth . You can't pass it if you hand it in , It has been debugged for a long time .
Code
There may be no interval covering the prefix , Therefore, it is best to let the initial value be the interval length ( It's equivalent to choosing only yourself ).
#include <cstdio> // JZM yydJUNK!!!
#include <iostream> // XJX yyds!!!
#include <algorithm> // XYX yydLONELY!!!
#include <cstring> // (the STRONG long for LONELINESS)
#include <cctype> // ZXY yydSISTER!!!
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long llong;
inline int readint(){
int a = 0, c = getchar(), f = 1;
for(; !isdigit(c); c=getchar())
if(c == '-') f = -f;
for(; isdigit(c); c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
inline void getMax(int &x, const int &y){
if(x < y) x = y;
}
const int MAXN = 105;
std::pair<int,int> a[MAXN];
int lef[MAXN], rig[MAXN][MAXN];
const int INF = 200000000;
int main(){
int n = readint();
rep(i,1,n) a[i].first = readint(), a[i].second = readint();
std::sort(a+1,a+n+1); // sort by COORD
for(int i=1; i<=n; ++i){
lef[i] = a[i].second; // only itself
for(int j=1; j!=i; ++j){
// last longest
if(a[j].first+a[j].second <= a[i].first)
getMax(lef[i],rig[i-1][j]+min(a[i].first
-a[j].first-a[j].second,a[i].second));
getMax(lef[i],lef[j]+min(a[i].first-a[j].first,a[i].second));
}
int l = a[i].first; // whatever
for(int j=i; j; --j){
// my longest
const int w = a[j].first+a[j].second;
l = std::min(l,a[j].first); // itself's left point
if(w >= a[i].first){
// really longer
rig[i][j] = w-l; // only itself
for(int k=1; k!=j; ++k){
// previous longest
getMax(rig[i][j],rig[j-1][k]+w
-max(a[k].first+a[k].second,l));
getMax(rig[i][j],lef[k]+w-max(l,a[k].first));
}
}
else rig[i][j] = rig[i-1][j]; // not to choose it
l = min(l,a[j].first-a[j].second); // be toL
}
}
int ans = lef[n]; // @a lef is non-decreasing
rep(i,1,n) getMax(ans,rig[n][i]);
printf("%d\n",ans);
return 0;
}
Postscript
Modelled on the Lanterns \text{Lanterns} Lanterns How to do it , Don't make decisions based on intervals , Make decisions based on coverage , At least it should be able to O ( n 2 log n ) \mathcal O(n^2\log n) O(n2logn) . take a i − l i , a i , a i + l i a_i-l_i,\;a_i,\;a_i+l_i ai−li,ai,ai+li Discretize together , Preprocessing g ( i , j ) g(i,j) g(i,j) For whether the inner interval can be used to cover the i i i Paragraphs to j j j paragraph . For a i i i, use Lanterns \text{Lanterns} Lanterns Approach is to O ( n log n ) \mathcal O(n\log n) O(nlogn) Of .
Pure mustard , It seems to be possible to do O ( n 2 ) \mathcal O(n^2) O(n2) . because S T \tt ST ST Table is O ( n log n ) \mathcal O(n\log n) O(nlogn) Of , The bottleneck is , Find the shape as h ( i ) ⩾ w j h(i)\geqslant w_j h(i)⩾wj Minimum i i i . If you put w j w_j wj Discrete out , For each f ( i ) f(i) f(i) Immediately update what it can be transferred to j j j, There is no dichotomy process . Be careful h ( i ) h(i) h(i) yes “ paragraph ” The number of , So it should be possible to pretreat O ( 1 ) \mathcal O(1) O(1) Find out the updatable interval .
Last , In fact, there are O ( n 2 ) \mathcal O(n^2) O(n2) Pure d p \tt dp dp practice , Has been O U Y E \sf OUYE OUYE After seeing the question 10 m i n 10\rm min 10min Internal thinking . I spent it. 2 h 30 m i n \rm 2h30min 2h30min Just think of O ( n 3 ) \mathcal O(n^3) O(n3) .
边栏推荐
- ArrayList扩容详解
- 2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
- February 16, 2022 Daily: graph neural network self training method under distribution and migration
- Irradiance, Joule energy, exercise habits
- Petrv2: a unified framework for 3D perception of multi camera images
- What is web application security testing technology?
- Equipment simulation and deduction training system software
- t10_ Adapting to Market Participantsand Conditions
- 开发那些事儿:EasyCVR平台添加播放地址鉴权
- Develop those things: add playback address authentication to easycvr platform
猜你喜欢
Htt [ripro network disk link detection plug-in] currently supports four common network disks
Domestic spot silver should be understood
Samba basic usage
Work and leisure suggestions of old programmers
Good looking UI mall source code has been scanned, no back door, no encryption
Bug of QQ browser article comment: the commentator is wrong
Source code of new campus errand / campus task platform on mutual station
People help ant help task platform repair source code
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Common design parameters of solid rocket motor
随机推荐
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
MES production equipment manufacturing execution system software
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
Is Huishang futures a regular futures platform? Is it safe to open an account in Huishang futures?
SLO is increasingly used to achieve observability | Devops
股票万1免5证券开户是合理安全的吗,怎么讲
How to learn automated testing?
At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
Euler function: find the number of numbers less than or equal to N and coprime with n
Is it safe to open an ETF account online? What are the steps?
Session layer of csframework, server and client (1)
To improve the efficiency of office collaboration, trackup may be the best choice
ZABBIX alarm execute remote command
聊聊项目经理最爱使用的工具
JDBC: deep understanding of Preparedstatement and statement[easy to understand]
transform. Forward and vector3 Differences in the use of forward
MySQL + JSON = King fried