Three-Resource 0/1 Knapsack
Problem statement
Each item has a value and consumes three independent resources. Select each item at most once without exceeding any of the three capacities, and return the maximum total value.
Function
maximizeKnapsackValue(values: int[], firstCosts: int[], secondCosts: int[], thirdCosts: int[], firstCapacity: int, secondCapacity: int, thirdCapacity: int) â intExamples
Example 1
values = [10,20]firstCosts = [1,2]secondCosts = [1,2]thirdCosts = [1,2]firstCapacity = 2secondCapacity = 2thirdCapacity = 2return = 20Case 1 exercises the documented deterministic contract.
Example 2
values = [6,10,12]firstCosts = [1,2,3]secondCosts = [2,1,2]thirdCosts = [1,2,1]firstCapacity = 4secondCapacity = 4thirdCapacity = 3return = 18Case 2 exercises the documented deterministic contract.
Example 3
values = [5]firstCosts = [0]secondCosts = [0]thirdCosts = [0]firstCapacity = 0secondCapacity = 0thirdCapacity = 0return = 5Case 3 exercises the documented deterministic contract.
Constraints
1 <= values.length <= 40.- All four item arrays have equal length.
0 <= costs and capacities <= 40.- Values are nonnegative and the answer fits a signed 32-bit integer.