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