The first time to write the slope optimization of the problem is good ah = =
But the question seems to be a dumb tat,
And then this is the article ... http://wenku.baidu.com/link?url= Uqoesurresum4nve5zachn8kak5hgztj5umfmzegjfqs6uvehq2s8zh7iitt7din47sfxztvy041l5tzdvltl1wsua35umiwfp8gqnpnues
S[i] is the prefix of c[i] and, F[i] represents the minimum cost of a 1th item to the first item.
The easy-to-get DP equation is f[i]=min (f[j]+ (s[i]-s[j]+i-j+1-l) ^2).
Set T[i]=s[i]+i, then F[i]=min (f[j]+ (t[i]-t[j]+1-l) ^2.
Set M=T[I]-L-1, then F[i]=min (f[j]+ (m-t[j]) ^2).
When I make a decision, J,k is set to 2 general decision points. Set j<k.
If K is superior to J, there is
f[k]+ (M-t[k]) ^2<f[j]+ (M-t[j]) ^2
Unfold, get
F[k]+m^2-2*m*t[k]+t[k]^2<f[j]+m^2-2*m*t[j]+t[j]^2
Simplify, get
((f[k]+t[k]^2)-(f[j]+t[j]^2))/(T[k]-t[j]) <2*m=2* (S[I]+I-L-1)
Make slope (i,j) = (F[I]+SQR ((double) s[i]+i)-f[j]-sqr ((Double) s[j]+j)/(s[i]+i-s[j]-j)
2 important conclusions of slope optimization (for this problem):
1) j<k, if Slope (j,k) <2* (S[I]+I-L-1), then K ratio J Excellent. (PS: The left side of the inequality is only a j,k-related equation, and the right side of the inequality is only the formula related to i)
2) J<k<l, if Slope (j,k) >slope (k,l), then K can be shed.
Monotonic Queue optimization DP pseudo-code:
for (int i=1; i<=n;++i) { while (H +1<t && slope (q[h],q[h+ 1]) <, ...) h++; F[i]=...; while (H +1<t && slope (q[t-2],q[t-1]) >slope (q[t-1],i)) t-- ; Q[t++]=i;}
View Code
"bzoj1010" [HNOI2008] Toy packing toy