HDU3507 Print artical

Source: Internet
Author: User

The main idea: there are N numbers a[n], each output continuous string, its cost is "this line number of squares plus a constant m". Ask how the output makes the total cost minimal. (n<=500000)

Analysis: The dynamic programming equation is: dp[i]=dp[j]+m+ (sum[i]-sum[j]) ^2;

One on the right is: sum[i]*sum[j]. Consider using a monotone queue.

Make Dp[i]=g,dp[j]+m+sum[i]^2+sum[j]^2=y,sum[j]=y,2*sum[i]=k

The upper formula becomes g=y-kx, that is, y=kx+g. This is a linear equation.

We want to make the G minimum, that is, we can consider a line with a slope of k from the bottom up, and set it to contact the first point is (XP,YP), p is the best decision point, so the best decision point of the set constitutes a lower convex package shape. Also because the slope K is 2*sum[i], as I increments, the slope k is incremented, so the points in the convex hull are monotonic and can be optimized using a monotone queue.

HDU3507 Print artical

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.