In this video we go over two solutions to the classic 0/1 knapsack problem, where a thief tries to maximize the value of items he can steal from a museum given that his knapsack can only hold a certain capacity.
The first (naive) solution is to try all possible ways of taking gems, but this is slow.
The dynamic programming (best) solution is to store the maximum value for each valid knapsack weight and item in a 2D array.
Link to webpage: www.srcmake.co...
Link to problem on hackerrank: www.hackerrank...
Twitter: / srcmake
Twitch: / srcmake
Discord: / discord
25 авг 2024