BZOJ1010 Toy Box Toy

Source: Internet
Author: User
BZOJ1010 Toy Box Toy Description

Professor P was going to see the Olympics, but he couldn't give up his toys, so he decided to ship all the toys to Beijing. He uses his own compressor to press
It can turn any item into a pile and then into a special one-dimensional container. Professor P has the number 1..N 1. N-N Toys, Part I I toys after compression into a one-dimensional length of Ci c_i. For ease of finishing, Professor P requires that the number of toys in a one-dimensional container be continuous. And if a one-dimensional capacity
There are a number of toys in the device, then two pieces of toys to add a unit-length of the filler, in the form of said if I toy to the J toy into a container, then the length of the container will be x=j−i+∑k=ijci x = j-i + \sum_{k = i}^{j} c_i the cost and capacity of the production container According to the professor, if the length of the container is X x, its production cost is (X−L) 2 (x-l) ^2. where l l is a constant. Professor P does not care about the number of containers, he can make containers of any length, even more than L L. But he wants the cost to be minimal.

Input

The first line enters two integers n,l. Next N lines enter Ci c_i. 1<=n<=50000,1<=l,ci<=107 1 Output

Output minimum cost Sample Input

5 4
3
4
2
1
4
Sample Output
1
Solution

Typical slope-enhanced DP
Order F[i] f[i] record the minimum required to compress all the toys from 1 1 To I I can get DP recursive f[i]=mini−1j=0 (f[j]+ (sum[i]−sum[j]+i−j−1−l) 2) f[ I] = Min_{j = 0}^{i-1} (F[j] + (Sum[i]-sum[j] + i-j-1-l) ^2) where Sum[i] sum[i] recording from 1 1 to

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.