For a class of state transfer equations can be written
F[i]=min/max (A[i]*b[j]+g[j]) +h[i] (A, H is a function only related to I, B, G is a function related only to J)
And A and b at least one is a monotone dynamic programming problem, we can optimize it by the combination of the number shape. This kind of problem is generally to divide a linear sequence into several paragraphs, the time complexity of the violent solution is generally o (n^2), if A and B are monotonous, can be optimized to O (n), if only one is monotonous, can be optimized to O (nlog2n).
Taking the minimum value as an example, consider deformation of the above equation, H[i] is obviously independent of the selection of the optimal transfer, can be erased first, the equation into-a[i]*b[j]+f[i]=g[j], the-a[i] as the slope, F[i] as the Intercept, this is a straight line, slope must, the minimum intercept. Will (B[j],g[j]) as the point of J, then we have to do is in the state transfer point of I corresponding to the minimum intercept point, that is, take a slope of-a[i] line from negative infinity upward translation, the first hit point. Obviously, this point must be on the convex hull of the I corresponding point set, and we are taking the minimum value, so it must be on the lower convex shell, and it is the tangent line to the convex hull. We want to maintain such a convex hull, which can be implemented in a monotone queue.
First of all, consider how to take out the optimal decision, set que is a horizontal increment with a convex point set, remove two points of the team head, if the line slope of the two points
Obviously the line is not tangent to the convex hull, and because the slope is monotonous (assuming that the increase), so the following line will certainly not be cut in this point, then directly to the team head pop-up. Always maintain this until the team head two point slope >=a[i], remove the team head transfer status can be.
Then consider the point I into the convex hull, set t1,t2 for the tail of the two points, K (i,j) for the I,j two point line slope, the slope of the lower convex hull is obviously increased, then if there is K (i,t1) <k (t1,t2), T1 there is no need to exist, delete it.
Maintenance is maintained until K (I,T1) >k (T1,T2) is present, guaranteeing the convexity of the point set saved by this queue.
Sometimes the slope and intercept are not completely monotonous.
Special treatment:
Horizontal axis monotonous:
The points on the two-point convex hull, to find such a point x , making
x and the x The line slope of the left point is less than the current line slope
x and the x The line slope of the left point is greater than the current line slope
Inserting a straight line, maintaining the convex hull
The slope is monotonous:
about the horizontal axis building a tree splay
and then in splay in-maintenance convex hull
Slope Optimization DP Learning notes