Loading topic
n items, each with a value and a weight. You may take each item at most once. The goal is the largest total value who3 min readsorted with a key does, and are comfortable with Big-O notation. It also assumes the problem statement from the first chapter: items have a value and a weight, and the knapsack has a capacity.3 min readbest(i, c). You should also be comfortable with nested Python lists and Big-O notation.3 min readdp[i][c] holds the best value using the first i items with capacity c, and you should be comfortable with nested Python lists.2 min readdp[i][c] from the earlier chapter, Python range with a negative step, and Big-O notation for space. The goal is to cut memory from O(nW) to O(W) without changing the answer.2 min readn + 1 rows and W + 1 columns, so it runs in O(nW) time. The bound looks polynomial. This chapter explains why it is not, and how that fits with the fact that 0/1 knapsack is NP-hard.2 min readdp[t] is the minimum weight needed to reach value exactly t. It also assumes you know why that DP's running time depends on the total value. If the values are huge, for example prices in cents up to 10^9, that tab3 min read