11/* 
2-  * 0-1 Knapsack Problem: Imagine you are a thief and you want to steal things with  room full of things. 
2+  * 0-1 Knapsack Problem: Imagine you are a thief and you want to steal things from  room full of things. 
33 * You have a knapsack which can handle maximum capacity of weight W, and you want to fill it up such  
4-  * that it's worth is maximum. Being an intelligent thief, you know weights and values of each item in room. 
5-  * How would you fill your knapsack, such that you get the maximum possible value. 
4+  * that it's worth is maximum. Being an intelligent thief, you know weights and values of each item in the  room. 
5+  * How would you fill your knapsack, such that you get the maximum possible value for your knapsack of capacity W . 
66 *  
77 * The problem essentially boils down to whether item i would be part of your loot or not. 
88 * This has optimal substructure: 
1414 * Then the maximum value of the loot is determined by remaining n-1 items whose possible weight would be 
1515 * W. (i.e excluding the ith item) 
1616 * 
17-  * We could get all subsets of possible items in your  loot, and choose the one with maximum value. 
17+  * We could get all subsets of possible items in the  loot, and choose the one with maximum value. 
1818 *  
1919 * Since this problem will have overlapping subproblems, we could use dynamic programming to solve it. 
2020 * So that we don't recurse to calculate the same subproblem which we have already calculated. 
@@ -64,4 +64,4 @@ int main()
6464    std::cout << " Maximum possible loot value for capacity " 
6565        << " : " maximum_possible_loot_value (weights, values, capacity) << std::endl;
6666    return  0 ; 
67- }
67+ }
0 commit comments