dp/slope optimization
According to the description of the topic it is easy to set out the Regulation equation: $$ f[i]=min\{f[j]+ (s[i]-s[j]+i-j-1-l) ^2 \}$$
where $ $s [i]=\sum_{k=1}^{i} C[k] $$
And $x$ is the $s[i]-s[j]+i-j-1$.
This $x$ 's expression is really not good-looking, we are easy to find that $i-j$ can actually be combined with $s[i]-s[j]$, even if $c [i]=c[i]+1$, then $s[i]=\sum_{k=1}^{i} (c[i]+1) =\sum_{k=1}^{i}c [I]+i $, so $x=s[i]-s[j]-1$. Then merge that $-1$ with $l$, that is $l=l+1$, and then we get the sorted equation: $$ f[i]=min\{f[j]+ (s[i]-s[j]-l) ^2 \} $$
Proof of decision Monotonicity: $ (J > K) $
\[\begin{aligned} f[j]+ (s[i]-s[j]-l) ^2 &< f[k]+ (s[i]-s[k]-l) ^2 \ f[j]-f[k]+ (s[j]^2-s[k]^2) &< (s[i]- L) * (s[j]-s[k]) \ \frac{f[j]-f[k]+ (s[j]^2-s[k]^2)} {(S[j]-s[k])} &< s[i]-l \end{aligned} \]
This will $s [i]-l$ as a whole to calculate
1 /**************************************************************2 problem:10103 User:tunix4 language:c++5 result:accepted6 time:132 Ms7 memory:2640 KB8 ****************************************************************/9 Ten //Bzoj 1010 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; at intGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*=Sign ; - } in Const intn=50010; -typedefLong LongLL; to /******************tamplate*********************/ + LL C[n],s[n],f[n]; - intQ[n],l,r; the DoubleSlopintKintj) { * return Double(F[j]+s[j]*s[j]-f[k]-s[k]*s[k])/ $ Double(2* (s[j]-s[k]));Panax Notoginseng } - intMain () { the intN=getint (), l=getint () +1; +F (I,1, N) { AC[i]=getint () +1; thes[i]=s[i-1]+C[i]; + } -F (I,1, N) { $ while(L<r && Slop (q[l],q[l+1]) <s[i]-l) l++; $ intt=Q[l]; -f[i]=f[t]+ (s[i]-s[t]-l) * (s[i]-s[t]-L); - while(L<r && Slop (q[r-1],q[r]) >slop (q[r],i)) r--; theq[++r]=i; - }Wuyiprintf"%lld\n", F[n]); the return 0; -}
View Code
"Bzoj" "1010" "HNOI2008" Toy packing toy