Solution: Maximum Value of the Loot
Solutions for the Maximizing the Value of the Loot Problem.
We'll cover the following
Solution 1: Recursive algorithm
Let’s define the price of a compound as /. A natural strategy for the thief is to keep taking as much of the priciest (most expensive) compound as possible. To prove that this strategy leads to an optimal solution, let’s consider the most expensive compound . What is the maximum amount of the -th compound that the thief can take into his backpack? First, it should fit into the backpack: . Second, it should not exceed the available amount of the -th compound: . Therefore, = . We claim that there is an optimum solution containing pounds of the -th compound.
To prove it, consider an optimum solution that maximizes the amount of the most expensive -th compound among all optimum solutions ( stands for the amount of the -th compound). If , then there is nothing to prove. Otherwise, . Therefore, and . Consider the following two cases:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.