The 0/1 Knapsack Problem - Dynamic Programming Method
Loading...
22,035
Loading...
Uploader Comments (Mindez)
see all
All Comments (62)
-
Thanks for the great explanation! :)
-
I didn't get the ending until I saw the comments you added about the video bugs. Cheers man, NOW it makes perfect sense.
Bazinga!
-
adamsın!adamın dibisin!
-
thank you , that was so helpful
-
Thank you ... really
-
Cheers man, helped a lot !
-
Cheers for reminding me of KILBURN
Loading...
Thank you :)..you remind me of Sheldon Cooper.
daftp27 2 months ago 5
@daftp27 Bazinga.
Mindez 2 months ago 4
thanks - this helps a lot! I have a question though - when you check if there is any space to fit another item, do you check for the maximum at that weight for rows above the current row? for examle if you're in row 3, and you have 2 weight units left over, do you check row 0, 1, and 2 (or maybe just row 2?) to check for the most you could fit?
hatsuharu333 7 months ago
@hatsuharu333 There cannot be a case where the number is higher further up. The highest number will always be in row 2. This is because when we populated row 2, we asked 'Is the number above bigger?' and if it was, we replaced it with that number. So we only need to check row 2, because it will ALWAYS be the maximum at that weight for the rows above the current row.
Mindez 7 months ago
What about the case where values do not matter? That is, if we only cared about filling up the knapsack to it's capacity or as close to it as possible? The answer for your particular example would be items one and two, in this case. But how would I go about finding this out using dynamic programming?
SaudadeSunday 1 year ago
@SaudadeSunday You could still model it like this, but set the values equal to the weights. That way you're trying to maximize the weights (ie. fit as much into the knapsack as you can), and everything has the same value/weight ratio so it's all about how much you can fit into the knapsack rather than how valuable it is.
Mindez 1 year ago