The basic steps of the dynamic programming algorithm (see Computer algorithm design and analysis P44)
- The properties of the optimal solution are analyzed and its structural characteristics are characterized.
- Defines the optimal value recursively.
- The optimal value is calculated in the bottom-up or top-down memory Method (Memo method).
- Based on the information obtained when calculating the optimal value, an optimal solution is constructed.
Step (1)-(3) is the basic step of dynamic programming algorithm. In the case where only the optimal value is required, step (4) can be omitted, and if an optimal solution to the problem is required, step (4) must be performed. At this point, when calculating the optimal value in step (3), it is usually necessary to record more information in order to quickly construct an optimal solution in step (4) According to the information recorded.
in the actual problem can also be done.
- The dividing stage: according to the question Time or the space characteristic, divides the question into several stages. Note that these stages must be ordered or sortable (i.e., no direction), otherwise the problem cannot be solved by dynamic programming.
- Select state: The various objective situations in which the problem is developed into various stages are expressed in different states. Of course, the choice of state to meet no-no validity.
- Determine the decision and write out the state transition equation: The two steps are put together because the decision-making and state transfer have a natural connection, state transfer is based on the previous stage of the state and decision-making to export the state of this phase. So, if we determine the decision, the state transfer equation is written out. But in fact, we often do this in turn, depending on the relationship between the States of the two adjacent paragraphs to determine the decision.
- Write the programming equation (including boundary conditions): The basic equation of dynamic programming is the general formal expression of the programming equation. Generally speaking, this step is relatively simple as long as the phases, States, decisions and state transitions are determined.
The basic steps of dynamic programming algorithm