Tree-shaped Backpack summary

Source: Internet
Author: User

The last two days have been plagued by a tree-shaped knapsack problem. The cause of all this was a knapsack problem, a problem that was done on Hackerrank a year ago.

The main topic is:

$ to a tree of N nodes, node I for a value of v[i], volume of s[i] goods. Another backpack with a volume m, requires a connecting block on the tree to be loaded into the backpack, \ \ Makes the total value of the selected item the most. $

Data range:

$N, m\le2000$

The naïve approach to complexity is $o (nm^2) $,tle. has not seen editorial, dragged to the present. Before doing this I have seen the Tri Tian wing of the backpack nine, while reading the 2009 national Training Team Xu Xianheng paper, "A few types of knapsack problem", Xu's paper mentions the tree-dependent knapsack problem has O (NM) solution, I am very happy, however, after watching and can not understand. Recently think of this problem, and then go through Xu's paper, tossing for two days, only to find:

  • Xu's paper is relatively brief, it is a bit difficult to understand
  • The tree-dependent knapsack problem discussed by Xu and a knapsack problem is not the same problem at all

The so-called tree-dependent knapsack problem in Xu's thesis refers to:

$ to a tree of n nodes, each node of the tree represents a value of v[i], volume of s[i] items. There is also a backpack with a volume m, which requires a connecting block with a root node in the tree to be loaded into the backpack, \ \ Makes the total value of the selected item the most. $

But with that in mind, I still don't understand Xu Xianheng's tree-type DP solution for $o (NM) $ for this issue. It took some effort to understand the basics:

$DP [I][j] indicates that node I and all of its ancestors (that is, the path of the root node to I \text{---} are all nodes on the p_i\text{---}), \ \ also select the maximum value of items not exceeding J in the left and subtree I of p_i. $

Tree-shaped Backpack summary

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.