Knapsack Problem
The Knapsack Problem is a classic puzzle in combinatorial optimization. Imagine you
are a hiker (or perhaps a slightly ethical thief) with a backpack that can only hold a
maximum weight. You are standing in front of a collection of items, each with its own
weight and value.
Your goal? Fill the bag to maximize the total value without exceeding the weight limit.
1. The Core Variants
Depending on the "rules" of the items, the problem changes significantly:
0/1 Knapsack Problem: You cannot break items. You either take the whole item
(1) or leave it (0). This is usually solved using Dynamic Programming.
Fractional Knapsack Problem: You can cut items (like gold dust or liquid). If the
bag is almost full, you can take a fraction of an item to maximize value. This is
solved using a Greedy Algorithm.
Bounded/Unbounded Knapsack: There are either limited copies or infinite
copies of each item available.