D - The Bakery CodeForces - 834D tree line optimization dp ···

D - The Bakery

 CodeForces - 834D 

This topic so hard ah, I understand for a long time, did not understand how good,

This segment tree optimization dp, the feeling is still very difficult.

Direct that the idea of ​​it, he could not see the code.

The subject of the transfer equation is well written,

DP [i] [j] indicates that the i-th maximum value of the cake into the j-th digit.

dp[i][j]=max(dp[k][j-1]+val[k+1~i]

Is obvious that this is certainly not seeking direct violence, it is necessary to use tree line optimization.

How to optimize segment tree it,

Look at this problem and give you a point x, at this point you ask the right end point of all sections of the number of species numbers,

This is very simple is not it, that you continue to ask from x to x + 1 point how this shift?

Is not found last [a [x + a [x + 1] position of the occurrence of this figure 1], from this position x + 1 +1 to this position, all of the sections are +1

This is not a segment tree is updated, then the position of each segment tree is not as we enumeration of i, each leaf node is l == r == k is not val [k ~ i]

I know this, and back to the previous question, we ask val [k + 1 ~ i] + dp [k] [j-1] of the maximum value

Because this dp [k] [j-1] has been seeking out the last time, this time no effect, and is a fixed value.

We just claim val [k + 1 ~ j]

It is possible to put these two things together inside the segment tree, it is a l == r == k this position, a position this is k + 1, it is necessary to move about Wang Qianmian val, or dp [k] back move about.

I choose the first, then is the time to update, updates the last [a [x + 1]] to the x position.

 

Guess you like

Origin www.cnblogs.com/EchoZQN/p/11353079.html