Python DP code giving Memory Limit Error


#1

def solve(self, A, B):
solvedValues=[]
for i in range(A+1):
solvedValues.append([])
for j in range(B+1):
solvedValues[i].append(-1)

    def solveUtil(A,B):
        if A==1:
            if B>9:
                return 0
            else:
                return 1
        if B==0:
            return 1
            
        if solvedValues[A][B]==-1:
            count=0
            for i in range(0,10):
                if B-i>=0:
                    #count+=solveUtil(A-1,B-i)
                    if solvedValues[A-1][B-i]==-1:
                        solvedValues[A-1][B-i]=solveUtil(A-1,B-i)
                    count+=solvedValues[A-1][B-i]
                else:
                    break
            solvedValues[A][B]=count
        return solvedValues[A][B]
            
    if A==1:
        if B>9:
            return 0
        else:
            return 1
    
    count=0
    for i in range(1,10):
        if B-i>=0:
            #count+=solveUtil(A-1,B-i)
            if solvedValues[A-1][B-i]==-1:
                solvedValues[A-1][B-i]=solveUtil(A-1,B-i)
            count+=solvedValues[A-1][B-i]
        else:
            break
    #for i in solvedValues:
    #    print(i)
    return count%1000000007

#2

same problem here anyone please reply