DEV Community

Discussion on: Solving the knapsack problem in PostgreSQL

Collapse
afzaalahmadzeeshan profile image
Afzaal Ahmad Zeeshan

Hi, care to explain this:

👕 T-Shirt (weight 10) + 🎩 Hat (weight 5) + 🧦 Socks (weight 3) for a total value of (7 + 15 + 10) = 32

If our max limit is 20, how is 32 the right choice? And, how many of these did we select to make the total of 32 (they add up to 18, if selected one item only, each).

Collapse
ftisiot profile image
Francesco Tisiot Author

Hi, 20 is the limit on WEIGHT, for which we are ok since 👕 T-Shirt (weight 10) + 🎩 Hat (weight 5) + 🧦 Socks (weight 3). The resulting VALUE is 32 because of 👕 T-Shirt (value 7) + 🎩 Hat (value 15) + 🧦 Socks (value 10)