Wine problem - TOP DoWn
def wineProblem(price ,i,j, year,dp):
if i > j:
return 0
if dp[i][j]!=-1:
return dp[i][j]
op1 = price[i]*year + wineProblem(price, i+1, j, year+1, dp)
op2 = price[j]*year + wineProblem(price, i , j-1, year+1, dp)
dp[i][j]= max (op1,op2)
return dp[i][j]
price = [2,3,5,1,4]
n=5
dp= [[-1]*50]*50
year =1
print(wineProblem(price , 0, n-1, year,dp))