Algorithm learning notes--dynamic programming method

Source: Internet
Author: User

First, the basic concept of dynamic planning process is: each decision depends on the current state, and then cause the transfer of state. A decision sequence is generated in the state of change, so the process of solving this problem by multi-stage optimization is called dynamic programming.
The basic thought and strategy are similar to the Division method, and the problem to be solved is decomposed into several sub-problems (stages). In order to solve the sub-stage, the solution of the former sub-problem provides practical information for the solution of the latter sub-problem. When solving any of the sub-problems. Various possible local solutions are listed, and the local solutions that are likely to achieve the best are preserved by decision, and other local solutions are discarded. Solve each sub-problem in turn, the last sub-problem is the solution of the initial problem.


Because the problem of dynamic programming solves mostly overlap sub-problem, for the reduction of repeated computation, each sub-problem is solved only once, and the different states of different stages are saved in a two-dimensional array.
The biggest difference between the method and the partition is: it is suitable for solving the problem by dynamic programming method. The sub-problems obtained by decomposition are often not independent of each other (that is, the solution of the next sub-stage is based on the solution of the previous sub-stage. For further solution).


Third, the application of the situation

There are 3 properties that can be used to solve the problem of dynamic programming:

(1) Optimization principle: The solution of sub-problems included in the optimal solution of the hypothetical problem is also optimal. The problem is called the optimal substructure. That satisfies the principle of optimization.

(2) No effect: that is, once a stage state is determined, it is not affected by the decision after this state.

In other words, the process after a state does not affect the state of the past, only the current state.

(3) There are overlapping sub-problems: That is, sub-problems are not independent, a sub-problem in the next stage of decision-making may be used more than once. (This nature is not a necessary condition for dynamic programming, but it is assumed to have no such property.) Dynamic programming algorithms have no advantage over other algorithms

Iv. Basic steps for solving the problem of dynamic programming is a multi-stage decision-making problem, which usually starts from the initial state. Through the choice of intermediate stage decision, the end state is reached. These decisions form a sequence of decisions that, at the same time, define an active route (usually the optimal activity route) for the entire process.

What you see. The design of dynamic planning has a certain pattern, generally going through the following several steps.
Initial state →│ decision 1│→│ decision 2│→ ... →│ decision n│→ End State

(1) Division stage: According to the problem of time or spatial characteristics. Divide the problem into several stages. In the partitioning phase, note that after the division of the stage must be ordered or sortable, otherwise the problem can not be solved.

(2) Determining state and state variables: the various objective situations in which the problem is developed into various stages are expressed in different states.

Of course. The choice of state is to satisfy no-no validity.

(3) Determine the decision and write out the state transition equation: There is a natural connection between decision making and state transfer. State transfer is the process of exporting the state of this phase based on the state and decision of the previous phase.

So the hypothesis determines the decision. The state transfer equation can also be written out.

But in fact, it is often done in turn, according to the relationship between the two stages of the state to determine the decision-making method and state transfer equation.

(4) Finding the boundary condition: the given State transfer equation is a recursive type, which requires a recursive termination condition or boundary condition.



So so. The phase, state, and state transfer decisions that are only to solve this problem are determined. The state transition equation (including boundary conditions) can be written.

Practical applications can be designed in a few simplified steps:

(1) Analysis of the properties of the optimal solution and characterization of its structural characteristics

(2) Recursive definition of optimal solution

(3) Calculate the optimal value from the bottom-up or top-down memory (Memo method)

(4) According to the information obtained when calculating the optimal value. The optimal solution of structural problems
Five, the algorithm realizes the main difficulty of the dynamic programming is the theoretical design. This is the determination of the above 4 steps, once the design is complete. The implementation section will be easy.
Solve problems with dynamic programming. The most important thing is to determine the three elements of dynamic planning:
(1) Stage of the problem
(2) Status of each stage
(3) The recurrence relationship between the previous phase and the latter one.
A recursive relationship must be a transition from minor problems to larger problems. From this point of view, dynamic programming can often be achieved by recursive programs, but because recursion can make full use of the solution of the previously saved sub-problems to reduce the repeated calculation, so for large-scale problems. There is the advantage of recursion, which is also the core of dynamic programming algorithm.



This paper determines the three elements of dynamic programming, and the whole solution process can be described by an optimal decision table, and the optimal decision table is a two-dimensional table. When a row represents the stage of a decision, the column represents the state of the problem. The data required to fill out the form generally corresponds to the optimal value (such as the shortest path) for this problem at some stage in a certain state. The longest common subsequence, maximum value, etc.), the process of filling in the form is based on a recursive relationship, starting from 1 rows and 1 columns. Fill in the form in the order in which the rows or columns are prioritized. Finally, the optimal solution of the problem is obtained by simple trade-offs or calculations based on the data of the whole table.

Algorithm learning notes--dynamic programming method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.