Algorithm · Snowflake · Medium
You have n item types. Item type i has weight 2^i and costs cost[i]. Determine the least money required to buy items whose total weight is no smaller than minWeight. Function Description: Implement the function minCostToReachWeight. Input Parameters: int cost[n]: the purchase price for each item type. int minWeight: the target minimum total weight. Returns: long_int: the smallest total purchase cost. Example: Suppose n = 4, cost = [3, 6, 10, 19], and minWeight = 17. An…
Checking your access…