cant understand the reccursion here (ans=max(ans,price[i] + solve(length, price, x-length[i], n))
def solve(length, price, x, n):
if x <= 0: # if x is negative or 0 return 0
return 0
ans = 0
for i in range(0, n):
if x >= length[i]:
ans = max(ans, price[i] + solve(length, price, x - length[i], n)) # recursive solution to find the maximum
return ans
plank_length = 4
length = [1, 2, 3, 4, 5, 6, 7, 8]
price = [2, 6, 8, 10, 14, 17, 19, 20]
n = 8
ans = solve(length, price, plank_length, n)
print("ans will be: " + str(ans))