# Knapsack-search (without replacement)
Last edited: 2026-01-28
# Statement
Knapsack-search (without replacement)
Given $n$ objects $o_i$ with weight $w_i$ and value $v_i$, and a goal $g$ is there a bag that has weight less than $B$ but value at least $g$. The solution to this is a subset of objects $S \subset \{1, 2, \ldots, n\}$ such that:
- $\sum_{i \in S} w_i \leq B$, and
- $\sum_{i \in S} v_i \geq g$.
If such a bag exists, return it; otherwise, report that no solution exists.
# Solutions
- First solution
- run time