Dynamic Planning I

Source: Internet
Author: User

This article is reproduced from http://yzfy.org/dis/listpost.php? Tid = 780, by macaroniz

Chapter 1 Dynamic Planning

First, let's look at an example:
Example 1: if there is a digital triangle array, compile a program to calculate a path from the vertex to the bottom, so that the number and maximum passing through the path. Each step can go down along the left slash or the right slash.
7
5 3
4 2 1
2 1 3 7
The essence of this problem is actually the longest path in a directed graph, which can be solved by classical graph algorithms or search.
Consider how to use the search method to solve this problem. expand from the first point, expand two feasible nodes each time until the bottom of the digital triangle is reached, and find the optimal value from all feasible paths, the complexity of doing so is O (2 ^ N). When n is large, the common search method will not be feasible.
It is found that the low search efficiency is largely due to a large number of repeated operations,Because for any node, the optimal value expanded from the start to the end is determined.This inspires us to make full use of the previous computation results.
Next we will conduct in-depth analysis, if you have already taken the J column of row I, then the maximum sum and S [I, j] s [I-1, J], s [I-1, in J + 1], the greater operator adds the value a [I, j] at (I, j), that is, the lower formula.
S [I, j] = A [I, j] + max (s [I-1, J], s [I-1, J + 1])
So we can start from the first line, push down the maximum sum and S of each position row by row, and finally select the largest one from the n s of the bottom row for the request, the complexity of this algorithm is O (n ^ 2). Compared with the search method, this algorithm has been greatly reduced,This method of making full use of the calculated results is called dynamic planning. 

Through the above example, we have a preliminary understanding of "Dynamic Planning". The problem it deals with is a "multi-stage decision-making problem ". The following concepts are defined:
Status(State): it indicates the nature of a thing, which is the number of "units" in "dynamic planning. For example, each node in Example 1 (the maximum value at the node) is in a single State.
PhaseStage: a stage is a set of states that are similar in nature and can be processed simultaneously. Generally, a problem can be divided into several stages in order of handling. For example, in Case 1, several nodes in each row form a stage. A stage can contain either multiple States or only one State. A variable describing the state of each stage is called a state variable. In example 1, s [4, J] can be used to indicate that the fourth stage (that is, the fourth row) reaches the maximum value of column J, that is, the status variable of Stage 4.
State transition equation: It is the evolution of the status of the previous stage to the latter. It is the equation about the state of two adjacent stages and the center of "dynamic planning.
In example 1: s [I, j] = A [I, j] + max (s [I-1, J], s [I-1, J + 1])
Decision: a selective action made at each stage. It is the choice that our program needs to complete. In example 1, max (s [I-1, J], s [I-1, J + 1])
The problem solved by dynamic planning is a "multi-stage decision-making problem", which generally starts from the initial state and ends with the decision-making in the intermediate stage. These decisions form a decision sequence and determine an activity route to complete the entire process (usually the Optimal Activity route)

From the above explanation, we can find that:Dynamic Planning is not like an algorithm, but more like a way of thinking..

Next, we will discuss the application scope of dynamic planning. To determine whether a problem can be used with dynamic planning, we need to consider two aspects:
I. Optimal sub-structure 
That is, the optimal solution of a problem only depends on the optimal solution of its subproblem. That is to say, the non-optimal solution has no effect on the solution of the problem. Let's take a look at the following question:
Example 2: There are four points, namely A, B, C, and D. Two adjacent points are connected to each other, indicating the length of each road. We define the path from A to D with the minimum length divided by 4 as the optimal path. Find an optimal path.

Many beginners often think that dynamic planning can also be used for this question, but this is not the case.
If the two roads of A-B are 2,3, the two roads of B-C are. If dynamic planning is adopted, the optimal value of Node B is 2 and the optimal value of node C is 2, but the optimal value of reaching node C is 0, that is, the line 3-1.
That is to say, the optimal value of C is not determined by the optimal value of B, and it does not have the optimal sub-structure.
It can be seen that not all "decision-making problems" can be solved by "dynamic planning. So,Only when a problem presents an optimal sub-structure can "Dynamic Planning" Be an appropriate candidate method.

Ii. No aftereffects 
That is to say, after a problem is divided into stages, the state in Phase I can only be obtained from the State in the stage I-1 through the state transition equation, and it has no relationship with other States, especially with the State that has not occurred, this is ineffective.

<End> >>>>>>>>>>>>>>
Classic question recommendations:
1. the maximum number of sub-sequence O (N ^ 2) versions is not decreased.
2. Longest Common subsequence
3. Minimum letter price tree
4. Merge stones
5. optimal binary tree
6. Work Arrangements
7. Backpack Problems
8. Extra Binary Tree
9. Coin Problems

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.