PPolySim OS
For Students · 0/1 Knapsack

0/1 Knapsack for a diet plan

Built for students learning it for a class or exam. See the concept move instead of memorizing formulas — and check your homework intuition. Simulate a diet plan live below — adjust the inputs and watch it respond, right in your browser.

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 →

More with 0/1 Knapsack

Frequently asked questions

Is this good for students?
Yes — this version of "0/1 Knapsack for a diet plan" is framed for students learning it for a class or exam. See the concept move instead of memorizing formulas — and check your homework intuition.
Do I need to install anything?
No. It runs in any modern browser, free, with no account required.