0/1 Knapsack
Try to solve the 0/1 Knapsack problem.
We'll cover the following
Statement
You are given items whose weights and values are known, as well as a knapsack to carry these items. The knapsack cannot carry more than a certain maximum weight, known as its capacity.
You need to maximize the total value of the items in your knapsack, while ensuring that the sum of the weights of the selected items does not exceed the capacity of the knapsack.
If there is no combination of weights whose sum is within the capacity constraint, return .
Notes:
- An item may not be broken up to fit into the knapsack, i.e., an item either goes into the knapsack in its entirety or not at all.
- We may not add an item more than once to the knapsack.
Constraints:
-
capacity
-
values.length
weights.length
values.length
-
values[i]
-
weights[i]
capacity