⚡ AlgoZen_
~/home/dynamic_programming/0/1_knapsack2 / 6

0/1 Knapsack

Advanced

Given items with weights and values and a capacity limit, maximize the total value. Uses a 2D DP table where each cell represents the best value achievable with i items and weight limit w.

time:O(n × W)
space:O(n × W)
⚡ +400_XP
step[1/20]
> Start
W=0
0
W=1
0
W=2
0
W=3
0
W=4
0
W=5
0
0/1 Knapsack: 3 items, capacity=5. dp[i][w] = max value using first i items with weight limit w.

// tap NEXT STEP to walk through one step at a time