Dynamic Planning-plan a company meeting

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/wenlei_zhouwl/article/details/5992704

Problem:Professor Stewart is a consultant to the president of a company who plans a company gathering. The company has a hierarchical structure, that is, the management relationship forms a tree rooted in the President. The Ministry of Human Resources ranks every employee as fond of gathering. This is a real number. The President does not want an employee and his/her immediate supervisor to participate in this gathering in order to make everyone enjoy it.
Professor Stewart faces a tree describing the company structure, using the left child and right brother notation described in section 10.4. In addition to pointers, each node in the tree also contains the employee's name and ranking of the employee's favorite parties. DescriptionAlgorithmWhich generates a list of guests, maximizing the total number of guests who like the party. Analyze the execution time of your algorithm.

Add two domains selectroot and unselroot to each node. Selectroot means that when the node is selected, the Child tree with the node as the root has the highest degree of liking. Unselroot means that when the node is not selected, the maximum degree of liking for the subtree with the node as the root is.
Assume that the two domain names and the degree of liking for each node are name and like. Initially, selectroot of each leaf node is its like value, and unselroot is 0.
Calculate the selectroot and unselroot values of each node in sequence.

In the end, you only need to check the President node and obtain the maximum value in selectroot and unselroot.
To record the guest list, you only need to start from the second layer of the tree and perform the following operations on each layer: if the parent is selected, the current layer is not selected; if the parent is not selected, the relationship between selectroot and uselroot of each node in the current layer is displayed. If selectroot is large, this node is selected. Otherwise, this node is not selected. After traversing the tree, the guests will be marked.
Calculate the selectroot and unselroot of N nodes. Each calculation only uses the Domain value of the subnode, therefore, the entire calculation process only accumulates the domain values of other nodes except the root node in the tree (each node is used once ). Therefore, the algorithm complexity is O (n ).

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.