Dynamic Planning III

Source: Internet
Author: User

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

Chapter 3 dynamic planning

In this chapter, we will learn about tree-based dynamic planning.
Dynamic Planning is generally divided into four categories: Linear Dynamic Planning, interval dynamic planning, tree-based Dynamic Planning and special types of dynamic planning.
Because linear models are closely related to interval models, we generally combine these two types for learning.
Tree-based dynamic planning is different from the preceding two types. It is implemented in a tree structure, so it is general,
Special types of dynamic planning, such as status compression,
The game and other problems can be summarized into this part, because the problems are scattered,
Therefore, please study this part by yourself. You can refer to the national training team papers over the years,
The discussion of this part is very thorough and in-depth.

Next let's learn about tree-based dynamic planning.
First, let's look at an example:
For example, given a tree T, each vertex u in the tree has a weight W (u), which can be a negative number.
Now we need to find connected subgraphs of tree T so that the sum of the weights of the subgraphs is the largest.
After analyzing this question, we found that for node A, if we consider a subtree with him as the root,
The optimal value is irrelevant to its parent node, so the transfer equation is:
F [I] = Sigma {f [son], when f [son]> 0 }+ W (u)
The final answer is the maximum value in F [X.
Because dynamic planning is performed in a tree, you may wish to write it in recursive form.

Through the above example, I believe you have a preliminary understanding of tree-based dynamic planning,
In fact, tree-based dynamic planning is a difficult problem in dynamic planning, because there are many constraints,
So it is not easy to transfer the status. The following is a difficult example:

Each side of a tree has a length value. You must select three vertices x, y, and z in the tree,
If the distance from X to Y is not greater than the distance from X to Z, and the distance from X to Y is the sum of the distance from Y to Z, the maximum value is obtained.
Number of vertices n <= 2000000
Because of the large data size, consider the O (n) or O (nlogn) algorithms.
Analysis of the problem, we found that because in a tree, there must be an intersection K in the path of X, Y, Z,
From S = XK + 2 * Ky + kz, we find that if we want s to reach the maximum value,
You only need Ky, XK, and KZ to set the maximum distance among the three trees with K as the root,
However, the time complexity is still O (N ^ 2,
After finding the distance from a node as the root for the first time,
You only need to use this point as the root and then traverse the DFS to find the distance of other nodes, so the total time complexity is O (n ).

I will try again to review the problem-solving ideas:We first determine the complexity of the algorithm from the data size,
Some properties are obtained through preliminary analysis of the model, and new solutions are obtained through these properties,
This is actually a general idea for solving tree-like dynamic planning and other problems.
.
By analyzing the particularity of the tree model, the time complexity can be greatly reduced.

Finally, let's look at a very divergent question:

FJ, a group of cows and numerous lands, has a narrow terrain farm which is divided into N pieces of land and N cannot exceed 1000.
The land is located in a straight line and numbered from left to right as 1 to n. Each piece of land has the same area,
But the height is not necessarily the same. Each land has an altitude value of no more than 1000000.
If a piece of land of the same height is lower on both sides or on the boundary of a farm, it will be called the "Top of the hill ".
FJ hopes to reduce the altitude of some land by moving soil away, so that the number of "mountain top" cannot exceed K, of which 1 ≤ k ≤ 25.
On this premise, FJ wants to minimize the volume of soil to be moved, that is, the height and minimum of all the land.

At first glance, this question seems to have nothing to do with tree-based dynamic planning, and there is no tree structure at all,
After analysis, we found that the so-called Mountain is the unconnected part of each layer, so from the perspective of the layer,
Obviously, each layer is related to its upper layer and its lower layer, and has nothing to do with the layer length. Therefore, the layer is not accessed as a vertex,
Ground-based nodes, each layer does not connect "blocks" as a node, and edge connections are used to connect adjacent points of different layers,
We are surprised to find that these points constitute a tree!
Further analysis shows that each time a top Hill is flattened, a leaf node is deleted from the tree,
The height can be regarded as the node weight. In this way, the problem is converted to deleting some nodes in the tree,
The complexity is O (NK ^ 2 ).

How clever! A seemingly complex problem is solved in this way,Use limitations as limitations, and use failures as methodsThis may be the charm of algorithms.

<To be continue> >>>>>>>>>> >>>>>
Recommended questions:
1. Maximum connected branches of the tree
2. Love snail bait
3. Long live the Queen
4. cable TV network
5. Greedy for nine birds
6. Treasure Hunt
7. Network Billing (noi2006)

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.