0 - 1 Knapsack Problem
Use dynamic programming to implement the solution of a problem.
We'll cover the following...
Problem statement
For each item, you are given its weight and its value. You want to maximize the total value of all the items you are going to put in the knapsack such that the total weight of the items is less than the knapsack’s capacity. What is this maximum total value?
The only condition is to consider all subsets of items. There can be two cases for every item:
- The item is included in the optimal subset.
- The item is not included in the optimal set.
Therefore, the maximum value that can be obtained from n
items is the maximum of the following two values:
- Maximum value obtained by
n - 1
items andW
weight (excluding item) - Value of