There're $N$ items numbered from $1\ldots N$, each item $i$ with a weight $w_i$ and a value $v_i$. The knapsack's capacity is $W$.
Some items could be selected only after a specific item have been put into the knapsack, or in other words,
some items depend on others.
+ $d_i = j$ $(i>j>0)$ means item $i$ depends on item $j$, you cannot choose item $i$ until you put item $j$ into the knapsack.
+ $d_i = 0$ $(i>0)$ means item $i$ does not depends on any other items.
It's guaranteed that each item depends on no more than one item. All the dependency relationships are vaild, no loop.
Maximize the sum of the values of the items in the knapsack so that the sum of the weights is no more than the knapsack's capacity.