A naive approach would be to generate all combinations of weights and calculate the profit of each combination. We would then choose the combination that yields the highest profit from among those that don’t exceed the knapsack capacity.
For example, suppose we’re given a knapsack with a capacity of , and the following list of values and weights:
To find the maximum profit, we try all possible valid combinations, that is, whose weight does not exceed :
| Weights | Values | Total Weight | Total Value |
|---|---|---|---|
A naive approach would be to generate all combinations of weights and calculate the profit of each combination. We would then choose the combination that yields the highest profit from among those that don’t exceed the knapsack capacity.
For example, suppose we’re given a knapsack with a capacity of , and the following list of values and weights:
To find the maximum profit, we try all possible valid combinations, that is, whose weight does not exceed :
| Weights | Values | Total Weight | Total Value |
|---|---|---|---|