knapsack.greedy_knapsack

A shopkeeper has bags of wheat that each have different weights and different profits. eg. profit 5 8 7 1 12 3 4 weight 2 7 1 6 4 2 5 max_weight 100

Constraints: max_weight > 0 profit[i] >= 0 weight[i] >= 0 Calculate the maximum profit that the shopkeeper can make given maxmum weight that can be carried.

Attributes

profit

Functions

calc_profit(→ int)

Function description is as follows-

Module Contents

knapsack.greedy_knapsack.calc_profit(profit: list, weight: list, max_weight: int) int

Function description is as follows- :param profit: Take a list of profits :param weight: Take a list of weight if bags corresponding to the profits :param max_weight: Maximum weight that could be carried :return: Maximum expected gain

>>> calc_profit([1, 2, 3], [3, 4, 5], 15)
6
>>> calc_profit([10, 9 , 8], [3 ,4 , 5], 25)
27
knapsack.greedy_knapsack.profit