First of all, the n^3 DP in this question is better.

F[I][J] Indicates the maximum height that can be achieved by using the first I lump sum and the topmost layer as the first j+1 package to the first package.

But the data range is still too big, so we need to think about the monotony.

----------------------------------------------------------------------------------------------------

From the other person's solution can be seen a conclusion we try to make the bottom of the shortest possible to gradually achieve the optimal

Then combined with the idea of recursion to do we will make the bottom of the shortest base on the second layer of the shortest and so on ...

However, based on this conclusion, I still have no definite idea of how to achieve this. But suddenly I think of such a set of data

3

2 1 4

We will find that only the first two bags can reach a height of 2, but with the 3rd package, it can only reach 1.

But if you push backwards, it's going to be a different story, because the parts are stacked directly on the ground floor.

So the answer to the backward push is monotonous.

Then we can use F[i] to record the minimum length of the bottom of the haystack with I to n packets G[i] record the maximum height that can be reached at this time

So we can optimize to n^2.

----------------------------------------------------------------------------------------------------

Next, we'll look at the recursive

F[i]=min (Sum[j-1]-sum[i-1]), j>i&&f[j]<=sum[j-1]-sum[i-1]

Obviously f[i] transfer from smaller J will result in better results (if the transfer condition is met) (*)

And for the transfer condition F[j]<=sum[j-1]-sum[i-1] we bashi sub-item get SUM[I-1]<=SUM[J-1]-F[J]

In this case, the greater the decision J obviously Sum[j-1]-f[j] the more it can be used as a decision-making basis (*) We know that J is as small as possible.

So if there is a decision K>J meet SUM[K-I]-F[K]>=SUM[J-1]-F[J] Then the decision K must not be used

So the problem changed to use a monotone queue to maintain the classic model of monotonic DP.

----------------------------------------------------------------------------------------------------

The implementation can refer to the code (however, if the above content is read seriously and will not be implemented by itself ...)

#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>#defineRep (i,n) for (int i=1;i<=n;++i)#defineIMAX (x, y) (x>y?x:y)#defineImin (x, y) (x<y?x:y)using namespacestd;Const intn=100010;intSum[n],f[n],g[n],q[n];intN;intMain () {scanf ("%d",&N); Rep (i,n) {scanf ("%d",&Sum[i]); Sum[i]+=sum[i-1]; } intIfront=1, itail=1; q[1]=n+1; for(inti=n;i;--i) { while(ifront<itail&&sum[q[ifront+1]-1]-sum[i-1]>=f[q[ifront+1]]) ++Ifront; F[i]=sum[q[ifront]-1]-sum[i-1]; G[i]=g[q[ifront]]+1; while(ifront<=itail&&sum[q[itail]-1]-f[q[itail]]<=sum[i-1]-f[i])--Itail; q[++itail]=i; } printf ("%d", g[1]); return 0;}

Bzoj 1233: [Usaco2009open] hay pile tower "idea question"