Luogu 3628
The SI represents the prefix of the sequence and
F (i) represents the maximum value of dividing the first I of a sequence by several segments
f (i) = Max{f (j) +a∗ (SI−SJ) 2+b∗ (SI−SJ) +c},1≤j
= Max{−2a*sj*si+f (j) +a*sj*sj−b*sj}+a*si*si+b*si+c,1≤j
1#include <cstdio>2#include <string>3 4typedefLong Longll;5 6 ll A, B, C;7 8 ll Read () {9ll x =0, F =1;Ten Charc =GetChar (); One while(!IsDigit (c)) { A if(c = ='-') F =-1; -c =GetChar (); - } the while(IsDigit (c)) { -x = (x <<3) + (x <<1) + (c ^ -); -c =GetChar (); - } + returnX *F; - } + All s[1000005], f[1000005];intq[1000005]; at -ll K (intj) { - return-2AS[j]; - } - -ll B (intj) { in returnF[J] + A * s[j] * S[J]-B *S[j]; - } to +ll Y (intIintj) { - returnK (j) * S[i] +B (j); the } * $ BOOLCoverintIintJintk) {Panax Notoginsengll y1 = (k (i)-K (k)) * (B (j)-B (i)); -ll y2 = (k (i)-K (j)) * (B (k)-B (i)); the returnY1 <=Y2; + } A the intMain () { + intn = read (); A = read (), B = Read (), C =read (); - for(inti =1; I <= N; ++i) { $ll x = Read (); S[i] = s[i-1] +x; $ } - intL =0, r =0; - for(inti =1; I <= N; ++i) { the while(L < R && Y (i, q[l]) <= y (i, Q[l +1])) ++l; -F[i] = Y (i, q[l]) + A * s[i] * S[i] + b * S[i] +C;Wuyi while(L < R && Cover (I, Q[r], q[r-1])) --R; theQ[++R] =i; - } Wuprintf"%lld\n", F[n]); -}
Apio 2010 Special Ops Team | Slope optimization DP