Dynamic Programming (summary)

 

example:

Digital Triangles

7

3 8

8 1 0

2 7 4 4

4 5 2 6 5

How to go from the top makes the weight go down, you can only go below or lower right, the whole journey, ask your greatest

specific methods:

1. The optimal solution to analyze problems, identify the nature of the optimal solution, and describe the structural characteristics:

The optimal solution: maximum weights of all the walk in is how much?

The nature and structure of optimal solutions: only equal to the maximum weight to the front line plus the maximum weight or being under the lower-right away, every line of this

Maximum of two directions to go in line

2. recursively define optimal value:

To find the optimal value from 0 starting line, it is necessary to find the optimal value starting from the first row

To find the optimal value starting from 1 line, it is necessary to find the optimal value starting from the second row

………………………

To find the optimum value of the third line of departure, it is necessary to find the optimal values ​​starting from the last row

Topic want you to seek the optimal value from 0 starting line, then we have to find the optimal value starting from the first row, with the optimal value line 0 to line 1

However, it is important, we need recursive solution, we must first solve the optimal value of the countdown starting from the first row, then according to the last row from the first

Hair optimal value calculated optimal value starting from the penultimate line

3. Calculation of the optimum value of the bottom-up manner

4. The optimum time to calculate the optimal value of the obtained information, configuration

This is to ask you specifically how to go, we need to save some of the information in time to solve the problem of the child, adoption construct optimal solution (the optimal value and

The optimal solution is different, the optimal value in this problem is a walk in the Law and the maximum value of that one, but the best solution is concrete moves

solution:

dp [i] [j]: representatives optimal value obtained i-th row and j are listed from

dp【i】【j】=max(dp【i+1】【j】,dp【i+1】【j+1】)+a【i】【j】

From the list represents the i-th row j-made optimum value is equal to the law that one of the biggest plus two kinds of weights i + 1 row of the starting point of the walk

From: "algorithm contest entry classic"
Reproduced: https: //blog.csdn.net/qq_39382769/article/details/80788294 

https://blog.csdn.net/u013309870/article/details/75193592

Guess you like

Origin blog.csdn.net/qq_42458302/article/details/88384675