Please read the new rule regarding the restriction on the use of AI tools. ×

kkbhss's blog

By kkbhss, history, 3 years ago, In English

I am trying to solve Dima and Hares using python and getting a runtime error I don't Know why. Can someone tell me why the error is coming ?

My code is:

dp = [[-1 for i in range(5)] for j in range(3005)]
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
def fun(i ,n ,idx):
    if dp[i][idx]!=-1:return dp[i][idx]
    if idx==0:
        if(i==n-1): return a[n-1]
        dp[i][idx] = max(fun(i+1,n,1) +a[i],fun(i+1,n,0)+b[i])
    else:
        if(i==n-1): return b[n-1]
        dp[i][idx] = max(fun(i+1,n,1)+b[i],fun(i+1,n,0)+c[i])
    return dp[i][idx]
print(fun(0,n,0))

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it