← 返回 snowflake 的题目列表Modified Knapsack Problem
类型:online_judge
Given n items, where the weight of the i-th item is 2^i, and the cost of the i-th item is cost[i], find the minimum amount needed to purchase the items such that the combined weight of the purchased items is at least minWeight.
Function Description:
Complete the function getMinimumCost.
Input Parameters:
int cost[n]: cost of each item.
int minWeight: minimum combined weight of the items.
Returns:
long_int: the minimum amount needed to purchase.
Example:
Consider n = 5 and cost = [2, 5, 7, 11, 25], minWeight = 26.
One of the optimal ways to purchase the items is as follows:
Buy 2 units of the 0-th item and 3 units of the 3rd item.
Total cost is 2 * 2 + 3 * 11 = 37.
Total weight is (2 * 2^0) + (3 * 2^3) = 26, which is at least minWeight.
Return the total cost of the items, 37.
Example
Input
5
2 5 7 11 25
26