Back to all solvers
0/1 Knapsack Solver
Maximize value under a weight capacity using classic dynamic programming — each item at most once.
Inputs
CSV: name,weight,value (+ optional capacity row). After Solve, also Export results CSV.
Weights should be non-negative integers for the DP table.
0/1 Knapsack
Select a subset of items to maximize total value without exceeding capacity W. Each item may be taken at most once (unlike the fractional knapsack).
Dynamic programming
V[i][c] = max( V[i−1][c], vᵢ + V[i−1][c − wᵢ] ) if wᵢ ≤ c
Fill a table for i = 1…n items and c = 0…W. Reconstruct the chosen set by tracing where the optimum improved.
Complexity
Time and memory O(nW). Works best when weights are moderate integers. For huge W, use approximation or branch-and-bound.
Capacity 10 with items A–D. Optimal set is A+B+D (weight 10, value 31).
Frequently Asked Questions
Each item is either left out (0) or taken fully (1). You cannot take a fraction of an item.