Problem p02683 (python)

Fixed submission:
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    #if (curr,tuple(prev)) in DP:
    #    return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res==float('inf'):
    print(-1)
else:
    print(res)

Buggy submission (verdict: Runtime Error):
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res==float('inf'):
    print(-1)
else:
    print(res)

Buggy submission (verdict: Runtime Error):
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res=='inf':
  print(-1)
else:
  print(res)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))

Buggy submission (verdict: Runtime Error):
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))