Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Problem 18: 0-1 Knapsack (Bonus: Subset Sum)

A topic by procmeal games created Sep 06, 2022 Views: 54
Viewing posts 1 to 1
HostSubmitted (2 edits)

The input is a list of n items that have a weight, w[i], and a value v[i].  Also, there is an integer maximum weight for the knapsack.  The goal is to make the highest value list of items where the total weight of the items is at most the max weight.  In other words, the sum of values should be maximized, but the sum of the weights can be at most the maximum weight.

It's "0-1" knapsack because each item is included either 0 or 1 times.

Here's a video: https://youtu.be/xCbYmUPvc2Q

This problem can be solved by dynamic programming.

Subset sum is a special case of this.  A video for subset sum: https://youtu.be/C0xiOGhS_js