Topic: Given a sequence, you can divide K-times, the score of each division is two series of the sum of the product to find the maximum score
First we can roll out the sequence of the segmentation sequence is not affect the score, for example, I want to split a sequence into four ABCD I first split a BCD or split AB CD final score is the same
Prove? Well...... Easy to pass. Obviously. Ha ha. Well, I'm not going to testify ... Just draw your own push and push.
Well, this is the Ben of God: Like I split the ABCD into AB CDs, A and a CD were all multiplied once, B, and the CDs were multiplied once again. A and B also multiply once to ensure that all sequence pairs (x, y) are only used once in any one of the tessellation methods.
And then it's obvious that we're making f[i][k] the largest fraction of K-blocks for the first element, then there is
f[i][k]=max{F[j][k-1] + sum[j]* (Sum[i]-sum[j])}
Make P=f[j][k-1]-sum[j]*sum[j]+sum[i]*sum[j]
Then there are sum[j]*sum[j]-f[j][k-1]=sum[i]*sum[j]-p
where X[j]=sum[j],y[j]=sum[j]*sum[j]-f[j][k-1],s[i]=sum[i], the query slope is monotonous, you can apply a monotone queue, maintenance under the convex package can be
Note that X may be equal when calculating the slope to be special
I this sand tea at the beginning actually thought F[i][1]=sum[i] ... Sandy can't afford it.
#include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define M 100100using namespace Std;typedef long long ll;struct point{ll x,y;double slope;point () {}point (ll _,LL __): X (_), Y (__), slope (0.0) {}}q[m];int n,k,r,h;int a[m];ll sum[m],f[m][2];inline double get_slope (const point & X,const Point &y) {if (x.x==y.x) return 2147483647* (y.y>x.y?1:-1); return (double) (y.y-x.y)/(y.x-x.x);} void Insert (point P) {double s=0;while (r!=h) {s=get_slope (q[r],p), if (r==h+1) break;if (S<q[r].slope) r--;elsebreak;} Q[++r]=p;q[r].slope=s;} Point Get_ans (double s) {while (r!=h+1&&q[h+2].slope<s) ++h;return q[h+1];} int main () {int i,j;cin>>n>>k;for (i=1;i<=n;i++) scanf ("%d", &a[i]), Sum[i]=sum[i-1]+a[i];for (j=2; j<=k+1;j++) {r=h=0;for (i=j;i<=n;i++) {Insert (point (sum[i-1],sum[i-1]*sum[i-1]-f[i-1][~j&1)));p oint p= Get_ans (Sum[i]); f[i][j&1]=sum[i]*p.x-p.y;}} Cout<<f[n][~k&1]<<endl;}
Optimization of Bzoj 3675 APIO2014 sequence segmentation slope