You’re in charge of buying coffee beans for your local coffee shop. In front of you are N piles of coffee beans. Each pile has a certain weight (for the whole pile), and an amount of profit you can make selling the coffee in that pile to people in your coffee shop. So, for example, you could have 3 piles:
a. Pile 1: Weighs 2 pounds, Sells for $5
b. Pile 2: Weighs 3 pounds, Sells for $4
c. Pile 3: Weighs 4 pounds, Sells for $7
You’re shopping yourself so you can only carry a certain amount of beans. (Suppose that amount is stored in a variable called “max_weight”. What should you take?)
(In the example above, if “max_weight” = 4 pounds, I should take all of pile 1, and half of pile 3, for a total profit of $8.50)
2007-11-11
21:16:37
·
4 answers
·
asked by
Jack Phan
1
in
Computers & Internet
➔ Programming & Design