"Algorithmic Reference" dynamic planning 1

Source: Internet
Author: User

1. What is dynamic planning

Dynamic programming, like the Division method, solves the whole problem by combining the solution of the sub-problem. But the difference is that the divide-and-conquer algorithm refers to dividing the problem into some independent sub-problems, solving each sub-problem recursively, and then merging the solution of the sub-problem to get the solution of the original problem. But the dynamic programming is suitable for the sub-problem is not the independent situation, namely each sub-problem contains the common sub-sub-problem. Dynamic planning solves each sub-sub-problem only once, saving its results in a single table, avoiding the recalculation of the answer each time each sub-problem is encountered.

2. several important properties in dynamic programming

2.1 Optimal sub-structure:

The first step in solving the optimization problem with dynamic programming is to describe the structure of the optimal solution. If an optimal solution of a problem contains the optimal solution of a sub-problem, the problem has an optimal substructure. When a problem has an optimal substructure, it is suggested that dynamic planning may be applicable (note that in this case, the greedy strategy may also be applicable) in dynamic programming, we use the optimal solution of sub-problems to construct an optimal solution to the problem. As an example, for the 0-1 knapsack problem, if F[I][J] indicates that the first item is considered, the backpack capacity is the maximum return value of the item in the backpack for J, then f[i][j] = max {f[i-1][j], F[i-1][j-v[i]] + p[i]} where P[i] For the value of the first item, then if F[I-1][J] or f[i-1][j-v[i] is not optimal, then f[i][j] will not be the optimal solution, which is the optimal sub-structure.

2.2 Repeat sub-problem:

The so-called overlapping sub-problem, both when a recursive algorithm calls the same problem constantly, we say that the optimal problem contains overlapping sub-problems, in response to this situation, two scenarios are proposed, namely: Memory search (that is, Memo algorithm), the second is: bottom-up recursion. This is also the key to DP thought. See the example of a digital triangle (see Rujia, "Algorithmic Race Primer classic"), repeating the case of D (3,2), D (4,2) and D (4,3).

2.3 Status:

State is a very important concept, if the algorithm based on clearance, then, the success of a topic design state, dynamic planning has completed the more than half . In fact, for a practical problem, if it can be identified by the DP method to solve, and can define the state, the problem will be enlightened. The next step is to find the coarse state transfer equation.

2.4 state transition equation:

The state transition equation is the core of the dynamic programming algorithm, and it is the key to realize the algorithm. The state of this stage in dynamic planning is often the result of the previous stage state and the previous decision. That is, the formula that is used from one state to another. For example, f[i][j in 0-1 backpacks] = max {f[i-1][j], F[i-1][j-v[i]] + p[i]}.

3. dynamic planning when to use

Dynamic planning is typically applied to optimization problems. There are a number of possible solutions to such problems, each with a value, and we want to find a solution with the optimal (maximum or minimum) value. The problem is called the "one" optimal solution to the problem (rather than the "deterministic" optimal solution), because there may be multiple values that take the optimal solution.

The basic conditions used in dynamic planning are:

1) Optimal substructure properties

2) overlapping properties of sub-problems

In the application of dynamic planning, for the recurrence of sub-problems, only in the first encounter when the solution, and save the answer, so that later encountered when the direct reference, do not have to re-solve, thereby greatly improving the efficiency of the problem solving. In contrast, the general search technology, for a sub-problem, whether or not has been solved, as long as the encounter, it will be solved again, thus affecting the efficiency of understanding the problem.

"Algorithmic Reference" dynamic planning 1

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.