当前位置:网站首页>[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) .
边栏推荐
- Domestic spot silver should be understood
- What are the legal risks of NFT brought by stars such as curry and O'Neill?
- An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
- Penetration practice vulnhub range Keyring
- Replace UUID, nanoid is faster and safer!
- Is it safe to open a securities account? Is there any danger
- Terms related to K line
- golang中的select详解
- Bug of QQ browser article comment: the commentator is wrong
- [C supplement] [string] display the schedule of a month by date
猜你喜欢

Check log4j problems using stain analysis

Cassette helicopter and alternating electric field magnetic manometer DPC

Penetration practice vulnhub range Tornado

Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?

t10_ Adapting to Market Participantsand Conditions

Yuancosmos game farmersworld farmers world - core content of the second conference in China!

How to use JMeter function and mockjs function in metersphere interface test

The new server is packaged with the source code of H5 mall with an operation level value of several thousand

Happy new year | 202112 monthly summary

Classpath classpath
随机推荐
t10_ Adapting to Market Participantsand Conditions
Definition of rotation axis in mujoco
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
Smart factory digital management system software platform
ZABBIX alarm execute remote command
Apache iceberg source code analysis: schema evolution
Win10+vs2019 Community Edition compiling OpenSSL
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Penetration practice vulnhub range Nemesis
Code example of libcurl download file
Check log4j problems using stain analysis
Fix the black screen caused by iPhone system failure
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
Euler function: find the number of numbers less than or equal to N and coprime with n
New patent applications and transfers
Talk about the favorite tools used by project managers
Function, condition, regular expression
網上股票開戶安全嗎?是否可靠?
Can hero sports go public against the wind?
Is the fund of futures account safe? How to open an account?