1010: [HNOI2008] Toy boxing toy time limit: 1 Sec Memory Limit: 162 MB
Submit: 8678 Solved: 3456
[Submit] [Status] [Discuss] 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 Toys, item I Toys
After compression becomes a one-dimensional length of ci. 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 saying that if I toy to the J Toys put to a
container, the length of the container will be X=j-i+sigma (Ck) i<=k<=j the cost of making a container is related to the length of the container, according to the professor,
If the container length is X, its production cost is (X-L) ^2. Where L is a constant. Professor P does not care about the number of containers, he can make any length of the capacity
Even more than L. But he wants the cost to be minimal.
Input
The first line enters two integers n,l. Next N Lines Enter ci.1<=n<=50000,1<=l,ci<=10^7
Output
Minimum cost of output
Sample Input5 4
3
4
2
1
4Sample Output1
Slope Optimization DP
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long Long#define maxn 50005using namespace Std;int n,l,l,r,q[maxn];ll s[maxn],f[maxn],g[maxn],h[maxn];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline double getk (int x,int y) {return (double) (F[x-1]+g[x]*g[x]-f[y-1]-g[y]*g[y])/(double) (G[x]-g[y]);} int main () {n=read (); L=read (); F (I,1,n) s[i]=s[i-1]+read (); F (i,1,n) g[i]=s[i-1]+i,h[i]=s[i]+i-l;l=1;r=0; F (I,1,n) {while (L<R&&GETK (Q[r-1],q[r]) >GETK (q[r],i)) R--;q[++r]=i;while (L<R&&GETK (q[l), Q[L+1])
bzoj1010 "HNOI2008" Toy packing toy