Saturday, August 10, 2013

Dynamic programming - memoization - knapsack problem

A thief enters a house and have a cloth to collect the items. The cloth has a fix capacity M. Thief can either select an item fully or leave that. Given the items with weight w1,w2,...wn and there values v1,v2,...vn. What is the maximum values he can collect.

For example -

item numberweightvalue
123
234
345
456

If the capacity of the cloth is 5, the thief can select item#1 and item#2 to make the (3+4=7) profit.

Code

No comments:

Post a Comment