Aoa5 Jency
Aoa5 Jency
CODE:
def knapSack(W, val, wt):
n = len(val)
if wt[i - 1] <= j:
else:
return {
"maxProfit": V[n][W],
n = len(val)
selectedWeights = []
selectedProfits = []
i, j = n, W
selectedWeights.append(wt[i - 1])
selectedProfits.append(val[i - 1])
j -= wt[i - 1]
i -= 1
return {"selectedWeights": selectedWeights, "selectedProfits": selectedProfits}
profit = [45, 55, 95, 130, 85, 35, 25] # Slightly adjusted profit values
W = 20
# Print results
OUTPUT: