复习斜率优化。。
显然得到dp方程为
f[i]=min{f[j]+(i-j-1+b[i]-b[j]-l)^2} j=1..i-1
其中b[i]为a[i]的前缀和。。
然后复杂度n^2,要优化。。
直接取j,k两点作差得。。当j比k优时
(f[j]-f[k])/(j-k+b[j]-b[k])+b[j]+b[k]+j+k<2*i+2*b[i]-2-2*L
然后用单调队列维护下凸包即可。。。
1010: [HNOI2008]玩具装箱toy
Time Limit: 1 Sec
Memory Limit: 162 MB
Submit: 12676
Solved: 5551
[Submit][Status][Discuss]
Description
P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京。他使用自己的压缩器进行压
缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中。P教授有编号为1...N的N件玩具,第i件玩具经过
压缩后变成一维长度为Ci.为了方便整理,P教授要求在一个一维容器中的玩具编号是连续的。同时如果一个一维容
器中有多个玩具,那么两件玩具之间要加入一个单位长度的填充物,形式地说如果将第i件玩具到第j个玩具放到一
个容器中,那么容器的长度将为 x=j-i+Sigma(Ck) i<=K<=j 制作容器的费用与容器的长度有关,根据教授研究,
如果容器长度为x,其制作费用为(X-L)^2.其中L是一个常量。P教授不关心容器的数目,他可以制作出任意长度的容
器,甚至超过L。但他希望费用最小.
Input
第一行输入两个整数N,L.接下来N行输入Ci.1<=N<=50000,1<=L,Ci<=10^7
Output
输出最小费用
Sample Input
5 4
3
4
2
1
4
Sample Output
1