@@ -0,0 +1,1424 @@
+# To get an insight into naive recursive way to solve the Knapsack problem%0A%0A%0A%22%22%22%0AA shopkeeper has bags of wheat that each have different weights and different profits.%0Aeg.%0Ano_of_items 4%0Aprofit 5 4 8 6%0Aweight 1 2 4 5%0Amax_weight 5%0AConstraints:%0Amax_weight %3E 0%0Aprofit%5Bi%5D %3E= 0%0Aweight%5Bi%5D %3E= 0%0ACalculate the maximum profit that the shopkeeper can make given maxmum weight that can%0Abe carried.%0A%22%22%22%0A%0A%0Adef knapsack(%0A    weights: list, values: list, number_of_items: int, max_weight: int, index: int%0A) -%3E int:%0A    %22%22%22%0A    Function description is as follows-%0A    :param weights: Take a list of weights%0A    :param values: Take a list of profits corresponding to the weights%0A    :param number_of_items: number of items available to pick from%0A    :param max_weight: Maximum weight that could be carried%0A    :param index: the element we are looking at%0A    :return: Maximum expected gain%0A    %3E%3E%3E knapsack(%5B1, 2, 4, 5%5D, %5B5, 4, 8, 6%5D, 4, 5, 0)%0A    13%0A    %3E%3E%3E knapsack(%5B3 ,4 , 5%5D, %5B10, 9 , 8%5D, 3, 25, 0)%0A    27%0A    %22%22%22%0A    if index == number_of_items:%0A        return 0%0A    ans1 = 0%0A    ans2 = 0%0A    ans1 = knapsack(weights, values, number_of_items, max_weight, index + 1)%0A    if weights%5Bindex%5D %3C= max_weight:%0A        ans2 = values%5Bindex%5D + knapsack(%0A            weights, values, number_of_items, max_weight - weights%5Bindex%5D, index + 1%0A        )%0A    return max(ans1, ans2)%0A%0A%0Aif __name__ == %22__main__%22:%0A%0A    import doctest%0A%0A    doctest.testmod()%0A

Create recursive_approach_knapsack.py (#7587)