"bzoj1010" [HNOI2008] Toy packing toy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.