Incorret question

i think the sample output given for given sample input is incorrect if i compare this question to this–https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem/0

if i’m wrong please correct me where iam understanding the question wrong

in GFG question link the first array is that of the cost associated
and 2nd is for weight of item

& its the opposite in the hackerblock link
first weights array is given then cost

otherwise the question is same

i have seen that but
5 4
1 2 3 2 2
8 4 0 5 3
but in a size of 4
“Total capacity = 4.
Pick size 1 with value 8 and size 2 with value 5” how can you fit (81+52)18 items(or 18 size)

no

u do not have to multiply the weight with the value

u are told the weight 2kg has value 5
and not 5*2

value is number of weights or not?

i am told the bag can carry a total of 4kg, now i have to fit different weights of correct value less than or equal to 4kg

yes so

1 2 3 2 2
8 4 0 5 3

means that 1kg bag has value 8
2 kg ->value is 4
3kg->0
2kg-> 5
2kg->3
so on choosing
1kg bag gives value 8
+2nd last 2kg bag gives value 5
hence adds upto 13

ok ok, understood, thank you for the help!

1 Like