def rob(l):
    dp=[0]*len(l)
    if(len(l)==0):
        return 0
    if(len(l)==1):
        return l[0]
    if(len(l)==2):
        return max(l[0],l[1])
    dp[0]=l[0]
    dp[1]=max(l[0],l[1])
    for i in range(2,len(l)):
        dp[i]=max(l[i]+dp[i-2],dp[i-1])
    return dp    

l=[6, 7, 1, 3, 8, 2, 4]
ans=rob(l)
print("max loot can be robbed :",ans[-1])

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: