Problem p03168 (python)

Fixed submission:
# import numpy as np
n=int(input())
l=[0]+list(map(float,input().split()))
n+=1
dp=[[0 for i in range(n)]for i in range(n)]
dp[0][0]=1
for i in range(1,n):
    for j in range(i+1):
        if j==0:
            dp[i][j] = (1-l[i])*dp[i-1][j]
        else:
            dp[i][j]=(1-l[i])*(dp[i-1][j])+l[i]*dp[i-1][j-1]
ans=0
# print(np.array(dp))
for i in range((n)//2,n):
    ans+=dp[-1][i]
print(ans)

Buggy submission (verdict: Runtime Error):
# import numpy as np
n=int(input())
l=input().split()
l=[float(x) for x in l]
t=(n+1)//2
dp=[[-1 for i in range(n+1)]for i in range(n+1)]
def recur(i,k,ans):
    if i==0:
        # global ans
        if k>=t:
            return 1
            
        return 0
    # a=dp[i][k]
    # dp[i][k]=recur(i+1,k+1,p*l[i],ans)+recur(i+1,k,p*(1-l[i]),ans)
    # b=dp[i][k]
    # if a!=0 and a!=b:
    #     print(a,b)
    # return dp[i][k]
    if dp[i][k]!=-1:
        return dp[i][k]
    
    dp[i][k]=l[i-1]*recur(i-1,k+1,ans)+recur(i-1,k,ans)*(1-l[i-1])
    # print(dp[i][k])
    # if dp[i+1][k+1] == 0:
    #     dp[i+1][k+1]=recur(i+1,k+1,p*l[i])
    # if dp[i+1][k]==0:
    #     dp[i+1][k]=recur(i+1,k,p*(1-l[i]))
    return dp[i][k]
# ans=0
# print(dp)
print("%0.10f"%recur(n,0,0))
# print(dp)
# print(ans)

Buggy submission (verdict: Runtime Error):
# import numpy as np
n=int(input())
l=list(map(float,input().split()))
t=(n+1)//2
dp=[[-1 for i in range(n+1)]for i in range(n+1)]
def recur(i,k,ans):
    if i==n:
        # global ans
        if k>=t:
            return 1
            
        return 0
    # a=dp[i][k]
    # dp[i][k]=recur(i+1,k+1,p*l[i],ans)+recur(i+1,k,p*(1-l[i]),ans)
    # b=dp[i][k]
    # if a!=0 and a!=b:
    #     print(a,b)
    # return dp[i][k]
    if dp[i][k]!=-1:
        return dp[i][k]
    
    dp[i][k]=l[i]*recur(i+1,k+1,ans)+recur(i+1,k,ans)*(1-l[i])
    # print(dp[i][k])
    # if dp[i+1][k+1] == 0:
    #     dp[i+1][k+1]=recur(i+1,k+1,p*l[i])
    # if dp[i+1][k]==0:
    #     dp[i+1][k]=recur(i+1,k,p*(1-l[i]))
    return dp[i][k]
# ans=0
# print(dp)
print("%0.10f"%recur(0,0,0))
# print(dp)
# print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
l=list(map(float,input().split()))
t=(n+1)//2
dp=[[-1 for i in range(n+1)]for i in range(n+1)]
def recur(i,k,ans):
    if i==n:
        # global ans
        if k>=t:
            return 1
            
        return 0
    # a=dp[i][k]
    # dp[i][k]=recur(i+1,k+1,p*l[i],ans)+recur(i+1,k,p*(1-l[i]),ans)
    # b=dp[i][k]
    # if a!=0 and a!=b:
    #     print(a,b)
    # return dp[i][k]
    if dp[i][k]!=-1:
        return dp[i][k]
    
    dp[i][k]=l[i]*recur(i+1,k+1,ans)+recur(i+1,k,ans)*(1-l[i])
    # print(dp[i][k])
    # if dp[i+1][k+1] == 0:
    #     dp[i+1][k+1]=recur(i+1,k+1,p*l[i])
    # if dp[i+1][k]==0:
    #     dp[i+1][k]=recur(i+1,k,p*(1-l[i]))
    return dp[i][k]
# ans=0
# print(dp)
print("%0.10f"%recur(0,0,0))
# print(dp)
# print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
l=list(map(float,input().split()))
t=(n+1)//2
dp=[[-1 for i in range(n+1)]for i in range(n+1)]
def recur(i,k,ans):
    if i==n:
        # global ans
        if k>=t:
            return 1
            
        return 0
    # a=dp[i][k]
    # dp[i][k]=recur(i+1,k+1,p*l[i],ans)+recur(i+1,k,p*(1-l[i]),ans)
    # b=dp[i][k]
    # if a!=0 and a!=b:
    #     print(a,b)
    # return dp[i][k]
    if dp[i][k]!=-1:
        return dp[i][k]
    
    dp[i][k]=l[i]*recur(i+1,k+1,ans)+recur(i+1,k,ans)*(1-l[i])
    # print(dp[i][k])
    # if dp[i+1][k+1] == 0:
    #     dp[i+1][k+1]=recur(i+1,k+1,p*l[i])
    # if dp[i+1][k]==0:
    #     dp[i+1][k]=recur(i+1,k,p*(1-l[i]))
    return dp[i][k]
# ans=0
# print(dp)
print(recur(0,0,0))
# print(dp)
# print(ans)