Given a set of items, each with a value and a weight, determine the subset of these items to include in a collection of limited capacity that maximizes the total value.
Explanation: Selecting the fraction with value 10 and weight 2, and then selecting a fraction of the item with value 5 and weight 1, to fill the remaining capacity, resulting in a total value of 10 + (2/2)*5 = 25.0/2 + 10 = 25.0
Explanation: Selecting the fraction with value 30 and weight 15, would exceed capacity, thus selecting the fraction with value 20 and weight 10, fills 10/12 of capacity, and then selecting a fraction of the item with value 15 and weight 5, to fill the remaining capacity, but that only fills 2/5 * 15 = 6, resulting in a total value of 20 + 10 = 30.0
Maximize value with greedy fraction selection
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak