Implementing a mathematical formula in python 3 : I want to implement the followin mathematical formula in python: 
optimal[i][s]=max{ optimal[i+1][s], optimal[i+1][s-J[i]] + V[i-1]  (s>J[i])}, i try the following:


    W={1:3,2:2,3:1,4:4,5:5,6:9,7:6,8:7}
    V=[25,20,15,40,50,55,45,58]
    optimal=[[]]
    J=list(W.values())
    s=12
    for i in range(1,len(W)):
        while J[i]<s:
            optimal[i][s]=max(optimal[i+1][s],optimal[i+1][s-J[i]]+V[i-1])
    print(optimal)

But i get an ERROR saying: list index out of range.
