Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

[Tutorial] Optimized solution for Knapsack problem

Revision en1, by sdnr1, 2018-05-21 15:47:22

Problem Statement

We are going to deal with the well known knapsack problem with an additional constraint in this blog. We are given a list of N items and a knapsack of size W. Every item has a cost ci and value vi associated with it (1 ≤ i ≤ N). We can select some items from the list such sum of the cost of all the selected items does not exceed W. The addition constraint is that . This is also known as the 0/1 knapsack problem.

The bounded knapsack problem

The bounded knapsack problem is like the 0/1 knapsack problem, except in this we are also given a count for each item. In other words, each item has a count si associated with it and we can select an item si times (1 ≤ i ≤ N).

Solving bounded knapsack problem

The solution is simple. Let dp[i][j] denote the maximum sum of value we can get while using first i items with a total cost of j

Tags #dp, knapsack

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en9 English sdnr1 2018-05-24 09:40:32 385
en8 English sdnr1 2018-05-22 22:02:49 17
en7 English sdnr1 2018-05-21 17:50:32 2 (published)
en6 English sdnr1 2018-05-21 17:45:34 25
en5 English sdnr1 2018-05-21 17:43:48 768
en4 English sdnr1 2018-05-21 16:42:51 460
en3 English sdnr1 2018-05-21 16:23:38 305
en2 English sdnr1 2018-05-21 15:58:49 12
en1 English sdnr1 2018-05-21 15:47:22 1023 Initial revision (saved to drafts)