Quick actions

cmd+k|ctrl+k

Navigation

Languages

ulloa

Snippet info

Language

Python

Visibility

public

Author

scssaluis

Created

2019-03-04T22:56:59Z

Updated

2019-03-04T22:57:17Z



def delico(T):
    n = len(T)
    t = [None]*(n+1) # 0 thru n inclusive
    t[0] = 0
    t[1] = T[0]
    
    for k in range(2, n+1): # already have solution for t[0], t[1]
        t[k] = max(t[k-2] + T[k-1], t[k-1]) # T[k-1] represents the usage of kth element (0-indexed)
    
    return t[n]
    

print(delico([1000, 1001, 1000]))

print(delico([21, 4, 6, 20, 2, 5]))



# def delico(T):
#     n = len(T)
#     t = [None]*(n+1) # 0 thru n inclusive
#     t[0] = 0
#     t[1] = T[0]
    
#     for k in range(1, n): # already have solution for t[0], t[1]
#         t[k+1] = max(t[k-1] + T[k], t[k]) # set solution for k+1
    
#     print(t)
#     return t[n]
    
# print(delico([1000, 1001, 1000]))
    

INFO