Skip to main content

0/1 Knapsack

Given item weights, item values, and a capacity, choose each item at most once to maximize total value without exceeding capacity.

Read the full walkthrough →
Visualization step 1 of 50. VISIT.
State
Vvisit
Step 1 / 50
DP Table
100%
dp[i][cap] means best value using the first i items within capacity cap.
item / cap
0
1
2
3
4
5
0 items
0
0
0
0
0
0
#1 w2/v3
0
0
0
0
0
0
#2 w3/v4
0
0
0
0
0
0
#3 w4/v5
0
0
0
0
0
0
#4 w5/v6
0
0
0
0
0
0
Step 1 / 50
Step 1 of 50. VISIT. Initialize the DP table with row 0 and capacity 0 as zero-value base cases.
Step Explanation1 / 50
VISIT

Initialize the DP table with row 0 and capacity 0 as zero-value base cases.

Output0 results
No output yet.