Knapsack Solver

One item per line as "weight,value" - pick the knapsack type and capacity to get the highest-value combination
Knapsack type:   Capacity:
Calculation Result Download CSV
No. Item Weight Value Picked count

Introduction to the tool and how to use it

The knapsack solver finds the most valuable packing that stays within capacity, in a single run. Enter one item per line in the format weight,value,
for example:
3,5
4,6
2,3
5,9
It uses classic one-dimensional dynamic programming: reverse-order roll for 0/1 knapsack, forward-order roll for unbounded knapsack, and records backtrace information to reconstruct the exact chosen set, so the combination truly reaches the optimal total value rather than a lone number. Capacity is capped at 100000 and items at 500; excess converges to the cap with a notice, so the browser never freezes.

How to use

  1. Choose the knapsack type:
       · 0/1 knapsack: each item selected at most once;
       · Unbounded knapsack: each item may be selected any number of times.
  2. Enter the capacity (a positive integer; a decimal rounds with a notice).
  3. Click Calculate; the results table shows how many times each item was selected plus a one-line summary, and the text box gives a written summary as well.
  4. Results support one-click copy and CSV export.

Message board

All messages →
0/200

  • No one has spoken up yet — want to go first?