def knapSack(W, wt, val, n):
    if n == 0 or W == 0:
        return 0
    if (wt[n-1] > W):
        return knapSack(W, wt, val, n-1)
    else:
        return max(val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),knapSack(W, wt, val, n-1))

val = [int(i) for i in input().split()]
wt = [int(i) for i in input().split()]
W = int(input())
n = len(val)
print("Maximum profit : " + str(knapSack(W, wt, val, n)))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: