dp+ slope optimization
First, we can find that the total score equals the sum of the products of the k+1 segment 22 (multiplication assignment law), which is irrelevant to the segmentation order.
Then we re-group the product (or the multiplication distribution law) we can convert to: $ans =\sum$ The sum of the first i-1 segment of the paragraph I x
So we can divide the number of times for the DP ~
F[I][J] indicates that the first J number is divided into the maximum score of the I segment, then there is $ $f [i][j]=max\{f[i-1][k]+sum[k]x (Sum[j]-sum[k]) \}$$ We observed that this equation is actually much like slope optimization ... and sum obviously satisfies monotonicity! So, to push the equation of decision Monotonicity. =
When the decision is K1<K2:
$$ \begin{aligned} f[i-1][k1]+sum[k1]* (Sum[j]-sum[k1]) &< f[i-1][k2]+sum[k2]* (sum[j]-sum[k2]) \ \ sum[j]* (sum[ K1]-SUM[K2]) &< f[i-1][k2]-f[i-1][k1]+sum[k1]^2-sum[k2]^2 \ sum[j] &> \frac{f[i-1][k2]-f[i-1][k1]+sum [K1]^2-SUM[K2]^2}{SUM[K1]-SUM[K2]} \end{aligned}$$
This question I was pit in: $sum [K1]-sum[k2]\leq 0$!!!
So when it comes to the slope, the denominator may be 0 ... So it can't be written in the form of slope, but into the last line of the kind ... But because there is a negative number, so also carefully consider the direction of the non-equal! Qaq
1 /**************************************************************2 problem:36753 User:tunix4 language:c++5 result:accepted6 time:18176 Ms7 memory:5180 KB8 ****************************************************************/9 Ten //Bzoj 3675 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#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 + using namespacestd; AInlineintGetint () { at 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 ; - } - Const intn=1e5+Ten, inf=~0u>>2; intypedefLong LongLL; - /******************tamplate*********************/ toLL f[2][n],a[n],sum[n]; + int from[n],n,m,q[n]; - DoubleSlopeintIintJintk) { thei=i&1; * return Double(f[i][k]-f[i][j]+sum[j]*sum[j]-sum[k]*sum[k]); $ }Panax Notoginseng intMain () { - #ifndef Online_judge theFreopen ("3675.in","R", stdin); +Freopen ("3675.out","W", stdout); A #endif theN=getint (); m=getint (); +F (I,1, n) a[i]=getint (), sum[i]=sum[i-1]+A[i]; -F (I,1, M) { $ intnow=i&1; $ intL=0, r=-1; q[0]=0; -F (J,1, N) { - while(L<r && Slope (i-1, q[l],q[l+1]) >=sum[j]* (sum[q[l]]-sum[q[l+1]]) l++; the intt=Q[l]; -f[now][j]=f[now^1][t]+sum[t]* (sum[j]-sum[t]);Wuyi while(L<r && Slope (i-1, q[r-1],Q[R]) * (Sum[q[r]]-sum[j]) >=slope (i-1, q[r],j) * (sum[q[r-1]]-SUM[Q[R]]) r--; theq[++r]=J; - } Wu } -printf"%lld\n",f[m&1][n]); About return 0; $}
View Code 3675: [Apio2014] sequence split time limit:40 Sec Memory limit:128 MB
submit:541 solved:202
[Submit] [Status] [Discuss] Description
Little H has recently been fascinated by a split-sequence game. In this game, small H takes a long
A non-negative integer sequence of degrees N is divided into k+l non-empty subsequence sequences. In order to get the K+l subsequence,
The small H will repeat the following steps seven times:
1. Small h first selects a sequence with a length of more than 1 (at the beginning of the small h only a length of n
Sequence one by one is the whole sequence obtained at the beginning);
2. Select a location and divide the sequence into contiguous two non-empty new
Sequence.
After each of these steps, small h will get a certain score. This is a score of two new sequences
The product of the elements in the column. Small h wants to choose an optimal partitioning scheme, so that after K-wheel (TH),
The total score for small h is the largest.
Input
The first line of the input file contains two integers n and Guineas (K+1≤n).
The second line contains n non-negative integers a1,n2 .... , an (0≤ai≤10^4), which represents the beginning of a small h
to the sequence.
Output
A row contains an integer that is the maximum score a small h can get.
Sample Input7 3
4 1 3 4 0 2 3
Sample Output108
HINT
"Sample description"
In the example, small H can get 108 points with the following 3-wheel operation:
1. -Start small H has a sequence (4,1,3,4,0,2,3). Small H selects the position after the 1th number
Divide the sequence into two parts and get the 4x (1+3+4+0+2+3) =52 points.
2. At the beginning of this round, small H has two sequences: (4), (1,3,4,0,2,3). Small h selection in 3rd number
The position after the word divides the second sequence into two parts and gets (1+3) x (4+0+2+
3) =36 points.
3. At the beginning of this round, small H has three sequences: (4), (1,3), (4,0,2,3). Small h selection in 5th
The position after the number divides the third sequence into two parts and gets (4+0) x (2+3) =
20 points.
After the three-wheeled operation, the small H will get four sub-sequences: (4), (1,3), (4,0), (2,3) and a total of 52+36+20=108 points.
"Data size and scoring"
: Data meets 2≤n≤100000,1≤k≤min (N-1,200).
Source [Submit] [Status] [Discuss]
"Bzoj" "3675" "APIO2014" sequence segmentation