The interesting thing about this problem is that there are so many ways to solve this problem. I’d recommend solving this problem by hand, no matter the algorithm you intend to use. You shouldn’t have to solve this problem via code.
Some methods you could use to solve this problem:
- Easy brute force
- dynamic programming (notice this problem is reducible to the Knapsack problem)
Anyways, my solution to the problem that fits all selected items in the 3kg remaining space and maximizes the total Preference index is to select the following
|WW2 Galilean binoculars||0.5kg||5|
Sum of selected item weights = 3.0kg
Sum of item preferences = 17
This problem is really easy but the point was to introduce you to the Knapsack problem.