"Study notes" slope optimization

Too long not touched the stuff, so it becomes a study notes.

Topic Features

In general, the slope dp will be optimized to give a little simpler than the other transfer equation dp.

Probably the formula:
\ [F [I] = A (I) B (J) + C (I) + D (J) \]
That is, different queues such that dp is monotonous and simultaneously and \ (i, j \) items related to, this time you need to use the slope optimization.

Take the title track might work better in terms of number.

P3195 [HNOI2008] toy packing

And to set the prefix \ (S (I) \) , then quickly dp equation:
\ [F [I] = \ {J min_ <I} \ {F [J] + (S (I) + I - S (j) - j - L -
1) \} \] provided \ (A (I) = S (I) + I, B (I) = A (I). 1 + L + \) .

Thus
\ [\ begin {aligned} f [i] & = f [j] + (a (i) - b (j)) ^ 2 \\ & = f [j] + a (i) ^ 2 - 2a ( i) b (j) + b
(j) ^ 2 \ end {aligned} \] transposing available
\ [2 a (i) b (j) + f [i] - a (i) ^ 2 = f [ j] + b (j) ^
2 \] order \ (B (J) = X, F [J] + B (J) = Y ^ 2 \) , then the equation can be seen as a plane rectangular coordinate system on a straight line.

At this time, \ (f [i] \) meaning becomes, when this line passes through the point \ (P (x, y) \) when the \ (Y \) intercept the axis plus \ (a (i) ^ 2 \) values ( \ (a (I) ^ 2 \) is a constant value).

So we just need to find the minimum value of the slope.

We can draw a diagram aid understanding. (FIG source oi-wiki, invasion deleted)

So we can use a monotonous queue at the convex hull maintenance on it.

Since this question, the slope is a monotonically increasing, so we can slope is less than the current head-of-slope point out all the shells, taken as a transition point to the first team.

P5504 [JSOI2011] Lemon

A first need to know the nature: the same size at both ends of the shell about each segment and this segment \ (S_0 \) is the size of the left and right ends of the shell.

Then consider dp, provided \ (f [i] \) representing the forward (I \) \ maximum number to obtain a number of lemon, \ (C_i \) indicates how many times this size appears.

Then there is
\ [f [i] = \
max_ {j \ leq i, s_i = s_j} \ {f [j - 1] + s_i (c_i - c_j + 1) ^ 2 \} \] to have all open : \
[F [I] = F [J -. 1] + s_ic_i ^ 2 - 2s_ic_ic_j + s_ic_j ^ 2 + 2s_ic_i-2s_ic_j + S_I \]
transposing available:
\ [F [J -. 1] - 2s_ic_j + s_ic_j ^ 2 = f [i] - 2s_ic_i
- s_ic_i ^ 2 + s_i + 2s_ic_ic_j \] order \ (C_J = X, \ \ F [J -. 1] - 2s_ic_j + s_ic_j ^ 2 = Y \) , can be like the one question as write a straight line.

So we convex hull for each color on a maintenance queue monotonous, since monotonically increasing slope, so we can point slope is less than the tail current of all flicked slope, while the tail is taken to a transfer point.

Guess you like

Origin www.cnblogs.com/cj-xxz/p/11727539.html