The calculation method of dynamic programming

Preface

Here I share with you the following my dynamic planning thinking method, I hope you can use it.

first step

The first step is to first calculate what is stored in the state, namely max, min, sum max, min, summ A X , m I n- , S U m and the like. This step can be done as long as you understand the topic.

Second step

The second part is to consider how to store the state, that is, fi, j, k,... F_{i,j,k,...}fi,j,k,...The i, j, k... I, j, k ...i,j,k . . . . If you are suredp dpd p must be a positive solution, then you can design it violently. That is, the memory is not burst, and the state transition equation can be exited, and the transition does not time out, then you can design this way.

third step

The third step is the most difficult step in dynamic programming: calculating state transitions. In fact, there are two methods for this step: the first is to find the rules, provided that you have time to write a violent program; the second, the classification, which can be divided into many categories, each category Both can be calculated by one formula, which is much more convenient, but more difficult.

the fourth step

The fourth step is to consider the boundary conditions. Considering the boundary conditions, we must do two things: 1. Before calculating a certain state, its sub-problems have been calculated; 2. Which ones can be directly calculated by hand, that is, the value is 0, 1 0, 1The state of constants such as 0 and 1 . If there is no constant state, you can also use the convenient calculation as the boundary. The rest should be set to a limit value, if it ismin minm i n is set to the maximum value,max maxm A X minimum,SUM SUMs u m can be set to0 00 wait.

the fifth step

The fifth step is to consider which state the answer is. According to the state designed in the first step, consider which states the answer contains, and find the best value or sum among these states.

Plan B

If the previous method cannot design dp dpd p , you are very sure aboutdp dpd p is a positive solution, then you can write adfs dfsd f s , guaranteedfs dfsThe parameters passed in d f s get the same value, so you can set a memory, and then optimize it. If you are afraid that the memorization constant is high, you can change it to the recursive form. This method can still solve most of the problems.

Guess you like

Origin blog.csdn.net/weixin_44043668/article/details/109137542