The monotone decision-making nature can be proved well. Use Kee Sum[i]=sigma (c[1],c[2] ..... C[k]); f[i]=sum[i]+i; C=L-1;
There are transfer dp[i]=min (dp[j]+ (f[i]-f[jk]-c) ^2); Suspended animation has 2 decision J<k, for I point, k decision better so can get
#include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <string> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring># Include <iomanip> #include <iostream> #include <algorithm>using namespace std;typedef long LL; const int inf = 0x3fffffff;const int mmax = 500010; LL C[mmax]; LL Dp[mmax]; LL sum[mmax];int N; LL l;struct node{int l,r; int D; Node () {} node (int l,int r,int D): L (L), R (R), d (d) {} void print () {printf ("%d%d%d\n", l,r,d); }}q[mmax]; ll Sqr (ll x) {return x*x;} void Up (int i,int j) {DP[I]=DP[J]+SQR (sum[i]-sum[j]+i-j-1-l);} bool OK (int i,int j,int d) {return Dp[d]+sqr (sum[i]-sum[d]+i-d-1-l) >=DP[J]+SQR (sum[i]-sum[j]+i-j-1-l);} int find (int l,int r,int j,int d) {int mid; r++; while (L<r) {mid= (l+r) >>1; if (OK (mid,j,d)) R=mid; else l=mid+1; } return R;} VoID make () {int head=0,tail=0; dp[0]=0; Q[tail++]=node (0,n,0); for (int i=1;i<=n;i++) {while (q[head].r<i) head++; if (q[head].l<i) q[head].l=i; Up (I,Q[HEAD].D); int tmp=0; while (Head<tail) {if (ok (Q[TAIL-1].L,I,Q[TAIL-1].D)) {tmp=q[tail-1].l; tail--; } else {tmp=find (Q[TAIL-1].L,Q[TAIL-1].R,I,Q[TAIL-1].D); Q[tail-1].r=tmp-1; Break }} if (Tmp<=n) Q[tail++]=node (tmp,n,i); }}int Main () {while (cin>>n>>l) {sum[0]=0; for (int i=1;i<=n;i++) {scanf ("%lld", &c[i]); Sum[i]=sum[i-1]+c[i]; } make (); printf ("%lld\n", Dp[n]); } return 0;}
dp[k]+ (f[i]-f[k]-c) ^2<dp[j]+ (f[i]-f[j]-c) ^2;
For a x>i hypothesis f[x]=f[i]+v; for decision J,k, if decision K is better than decision J, it must
dp[k]+ (f[x]-f[k]-c) ^2<dp[j]+ (f[x]-f[j]-c) ^2;
So dp[k]+ (f[i]+v-f[k]-c) ^2<dp[j]+ (f[i]-v-f[j]-c) ^2;
As long as 2v (f[i]-f[k]-c) +v^2<2v (f[i]-f[j]-c)
Better than v>0 F[k]>f[j] This is inevitable, so it can be very good to prove the nature of monotone decision-making, and then according to the "1D/1D Dynamic planning Preliminary" paper.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 1010 (monotonic decision Optimization)