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