Imagine you're a clever thief with a knapsack. You've broken into a store with various items, each with its own weight and value. Your goal is to fill your knapsack with the most valuable combination of items without exceeding its weight capacity. Choose wisely!
We'll use dynamic programming to solve this problem. We'll create a 2D array where each cell [i][w] represents the maximum value we can achieve with the first i items and a knapsack capacity of w. We'll build this table step by step, considering each item and each possible capacity.
Item / Capacity |
---|
Step: 0 of 3
Explanation:
The maximum value that can be achieved with a knapsack capacity of 5 is: