PPolySim OS

0/1 Knapsack

Pack the most valuable haul without overloading the bag. The knapsack problem looks simple but defeats greedy strategies — dynamic programming cracks it.

0/1 KnapsackLive
Camera
4 kg
$500
packed
Laptop
8 kg
$700
packed
Water
3 kg
$200
packed
Tent
10 kg
$400
left
Food
5 kg
$300
packed
Book
2 kg
$90
left
Radio
6 kg
$260
left
Rope
3 kg
$130
left

Controls

Presets

The knapsack problem: pick items to maximize value without exceeding a weight limit. Greedily grabbing the most valuable item fails; the optimal answer needs dynamic programming, which builds a table of best values for every capacity. It models budgeting, cargo loading, and resource allocation — and is a classic NP-hard problem solved efficiently by DP.

▶ Run in Python

Data Inspector

Total value$1700
Weight used20 / 20 kg
Items packed4

Governing equation

Reading this result: DP fills all 20 kg for $1700; notice the best pack is not simply the highest-value items — it trades value against weight, which is exactly why greedy selection fails here.

Runs locally in your browser — free forever. Scale to the cloud when reality gets heavy.

or unlock everything with Pro →
★ Sign in to save this setup
Save your tuned setup, or drop this simulation into your own site, docs, or course page.

How it works

Given items with weights and values and a capacity limit, the 0/1 knapsack problem chooses a subset of maximum value. Grabbing the highest-value or best-ratio item first can be badly suboptimal, so the solution builds a table of the best achievable value for every capacity. It models budgeting, cargo loading, and portfolio selection — a classic NP-hard problem tamed by DP.

Ask the AI about this model

The math, the assumptions, real-world uses, or a code translation — explained for this exact simulation.

More Optimization simulations

Frequently asked questions

Is this knapsack problem solver tool really free?
Yes. 0/1 Knapsack runs entirely in your browser using your device's own compute, so local use is free forever. You only pay Compute Tokens if you scale a job to the cloud.
Do I need to install anything?
No. Everything runs client-side in a modern browser — no downloads, no license, no account required to start.
Can I save or share my simulation?
Create a free account to save projects, and use a shareable embed or minted DOI to publish a live, interactive version anywhere.
How accurate are the results?
The solver uses established numerical methods, but results are for research and educational purposes and should be validated against experiment or professional review before you rely on them.