BZOJ-1911 特别行动队
DP+斜率优化
就不再多说了。。。还是基础的斜率优化。。。
-
var
-
n,i,s,t,a,b,c,xa,xb,xc:longint;
-
num,dp,xl,sum,s2:array[0..1000005] of int64;
-
-
begin
-
read(n,xa,xb,xc);
-
for i:=1 to n do read(num[i]);
-
for i:=1 to n do sum[i]:=sum[i-1]+num[i];
-
s:=1;t:=1;
-
for i:=1 to n do
-
begin
-
while s<t do
-
begin
-
a:=xl[s];
-
b:=xl[s+1];
-
if 2*xa*sum[i] < (s2[b]-s2[a])/(sum[b]-sum[a]) then
-
begin
-
xl[s]:=0;inc(s);
-
end
-
else break;
-
end;
-
a:=xl[s];
-
dp[i]:=dp[a]+xa*sqr(sum[i]-sum[a])+xb*(sum[i]-sum[a])+xc;
-
s2[i]:=dp[i]+xa*sqr(sum[i])-xb*sum[i];
-
inc(t);
-
xl[t]:=i;
-
while t-s>1 do
-
begin
-
a:=xl[t-2];b:=xl[t-1];c:=xl[t];
-
if (s2[b]-s2[a])/(sum[b]-sum[a]) < (s2[b]-s2[c])/(sum[b]-sum[c]) then
-
begin
-
xl[t-1]:=xl[t];xl[t]:=0;dec(t);
-
end
-
else break;
-
end;
-
end;
-
write(dp[n]);
-
end.