The movement of this person is similar to the 77C-Beavermuncher-0xFF to find the last point that can be traveled most.
Practice: Suppose a person finally returns to J, can walk through the most point, can first find the i-0-i, I-n-I, can walk through the most points, this can be directly greedy, the point where the bridges between I-n are collapsed can be the most common.
You can also find the sum [I] of the vertices that can be done at most without passing through the two-point range.
Then DP [J] = sum [J]-sum [I] + left [J] + right [I] = sum [J] + left [J] + left [I] -sum [I], this can be recorded in a monotonous queue.
This type of question should first enumerate the starting point and the ending point, and then judge the going back and not going back. The movements here can be categorized. Do not be confused by situations that seem unnecessary at the beginning.
# Include <vector> # include <algorithm> # include <cstdio> # include <cstring> # include <queue> # define ll long longconst int LMT = 100005; using namespace STD; ll lef [LMT], rig [LMT], sum [LMT], Bri [LMT]; struct comp {bool operator () (const int I, const Int J) {return lef [I]-sum [I] <lef [J]-sum [J] ;}}; priority_queue <int, vector <int>, comp> que; int main (void) {int N; ll ans = 0; scanf ("% d", & N); For (INT I = 1; I <n; I ++) {scanf ("% I64d", & Bri [I]); If (BRI [I]> = 2) lef [I] + = lef [I-1]; lef [I] + = Bri [I] & 1? Bri [I]-1: Bri [I]; sum [I] + = sum [I-1] + (BRI [I] & 1? Bri [I]: Bri [I]-1) ;}for (INT I = n-1; I> = 0; I --) {rig [I] + = Bri [I + 1] & 1? Bri [I + 1]-1: Bri [I + 1]; If (BRI [I + 1]> = 2) rig [I] + = rig [I + 1]; // depends on !!} For (INT I = 0; I <n; I ++) {que. push (I); ans = max (ANS, Lef [Que. top ()]-sum [Que. top ()] + sum [I] + rig [I]);} printf ("% i64d \ n", ANS); Return 0 ;}