Problem 545165 · medium · Phase 05 Advanced Algorithms & Graphs

Bottomless Supply Crates

dynamic programming · unbounded knapsack

A cargo drone can lift at most capacity kilograms. The depot has an unlimited supply of each product type: type i weighs weights[i] kilograms and earns values[i] credits per unit delivered. Return the largest total of credits for a single flight.

Examples

Input:  weights = [2, 3], values = [3, 5], capacity = 7
Output: 11
Explanation: two units of type 0 and one unit of type 1 weigh 7 and earn 3 + 3 + 5.

Input:  weights = [4], values = [9], capacity = 3
Output: 0

Constraints

  • 1 <= len(weights) == len(values) <= 100
  • 1 <= weights[i] <= 2000, 0 <= values[i] <= 10**4
  • 0 <= capacity <= 2000
  • Target complexity: O(n * capacity).

Goals

  • Allow each item type to be used any number of times
  • See how the loop direction changes the meaning of the table
Starting Python…