Poj 1947 rebuilding roads (tree backpack DP)

Source: Internet
Author: User

From http://blog.csdn.net/shuangde800

Link: poj-1947

Question

To a tree, ask at least a few sides to delete, so that the number of nodes in the remaining subtree is P.

Ideas

I read this question a few days ago, but I have no idea. I think about it every day. Today, I still have doubts about my methods.
In the case of, even ac ..

F (I, j) indicates subtree I, which retains the minimum number of edge deletions for J nodes. Note that the subtree OF THE J nodes is the root node.
Subtree with J nodes for I. In this way, it is easy to think about state transfer.

For subtree I, if only one node is retained, the edge connecting all its son nodes must be deleted,
Therefore, you can initialize f (I, 1) = node I's son count.

F (I, j), that is, the subtree I retains J nodes, so for each subtree of I, you can choose to retain 1, 2,... J-1 nodes
Then each subtree can be considered as a group of items, and all the subtree is grouped into a backpack.

If the sub-tree v chooses to retain K points, then the sub-tree I will retain J-K points.

So transition from status:
F (I, j) = max {f (I, j-k) + f (v, k) -1 | 1 <= k <s} | V is the son node of I}

Eventually ans = min {f (I, p) | 1 <= I <= n}

Code

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.