Colorfull Knapsack problem

please explain me below output

sample input

9 3 10
1 3 5 1 3 5 1 3 5
1 1 1 2 2 2 3 3 3

sample output

1

Here what you have to do is take exactly M colors and minimize the unused capacity that means maximize your weight in knapsack.
For this example -:
9 3 10
1 3 5 1 3 5 1 3 5
1 1 1 2 2 2 3 3 3
You have option of taking 3 colors in such a way that minimize the unused capacity, so your options will be -:

  1. take color 1 of weight 5 , take color 2 of weight 3 , take color 3 of weight 1 => Unused capacity = 10 - ( 5 + 3 + 1) = 1.
  2. take color 1 of weight 3 , take color 2 of weight 3 , take color 3 of weight 1 => Unused capacity = 10-(3 + 3 + 1) = 3.
    Similarly you have more options and the one which gives minimum unused capacity is your ans.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like