The principle of dynamic programming

Source: Internet
Author: User

The dynamic programming is similar to the divide-and-conquer method, which solves the original problem by the solution of the combinatorial sub-problem.

Dynamic programming is often used to solve optimization problems (optimization problem). There are a number of possible solutions to such problems, each of which has a value, and we want to find the solution of the optimal value (maximum or minimum value). We call this solution an optimal solution to the problem (Oneoptimization solution) rather than (theoptimization solution), because there is a possibility that multiple solutions are at an optimal value, But in solving the original problem of the optimal solution, only need to find one of them. Just like the matrix chain multiplication problem, when choosing the best division position k, it is only necessary to determine whether the new cost is smaller than the previous selected K, if not small, the value of K is not changed. This shows that it is possible to have another split position with the current record of the location of the k is the same price, this shows that K is the best division of the location of more than one, that the original problem may not be the optimal solution, but the dynamic programming is to find an optimal solution to the original problem.

A dynamic programming algorithm is usually designed according to the following four steps:

1. Describe the structural characteristics of an optimal solution;

2. Recursively define the value of the optimal solution;

3. Calculate the value of the optimal solution, usually using the bottom-up method;

4. Using the calculated linear structure an optimal solution.

The two elements that use dynamic programming to solve problems are the overlapping of optimal substructure and sub-problem respectively.

(1) Optimal substructure

If the optimal solution of a problem contains the optimal solution of its sub-problem, we call this problem to have the optimal substructure property. Therefore, whether a problem is suitable for the application of dynamic programming algorithm whether it has the optimal substructure property is a good clue (of course, having the best substructure property may also imply the application of greedy strategy).

In dynamic planning, the optimal substructure is usually used from the bottom up. First, the optimal solution of sub-problem is obtained, then the optimal solution of the original problem is obtained by selecting it. In the process of solving the problem, we should choose the sub-problems involved, and select the sub-problem that can get the optimal solution of the original problem.

When using the dynamic programming algorithm, it is irrelevant to ask the sub-problem of the solution of the original problem, which is irrelevant, because the optimal solution of the problem can be obtained by solving the optimal solution of sub-problem A and B by two two sub-problems, A and B, respectively, given the original problem p. And the solution of sub-problem A and B is irrelevant, and the solution of the original problem of A and B is not coincident except at the place where the interface is the best solution. This sentence is actually very good understanding, such as matrix multiplication in AI by AJ, divided into two sub-problem AI to AK and a (k+1) and AJ, respectively, to find the solution of the two sub-problems, two sub-problem of the release of the AK is coincident, and no repetition in other places.

(2) Overlapping sub-problems

If the recursive algorithm solves the same sub-problem repeatedly in the process of solving, it is said that the optimization problem has the properties of overlapping sub-problems. This place says that the set of sub-problems to be decomposed in the process of solving the original problem solved by recursive algorithm is fixed. In contrast, the problem that is suitable for solving by divide-and-conquer is usually a new sub-problem in every step of recursion.

The dynamic programming algorithm usually uses overlapping sub-problems to solve the problem of each sub-problem once, the solution is stored in a table, when the sub-problem is needed to look directly at the table, the representative of each table is a constant time.

In order to solve the problem of matrix multiplication, a top-down dynamic programming algorithm with a memo can be used, and a bottom-up dynamic programming algorithm is also available.


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.