Knapsack 0-1 path reconstruction (which items to take) [duplicate]
问题 This question already has answers here : How to find which elements are in the bag, using Knapsack Algorithm [and not only the bag's value]? (4 answers) Closed 6 days ago . I know how to solve knapsack 0-1 problem with dynamic programming approach, but I am having troubles figuring out which items to take without compromising the complexity of O(N * C) (N items, C capacity). Any ideas (I would prefer a bottom-up approach)? 回答1: Suppose, right now you're storing results in array bool[] a ,