Why same memoization solution reach max depth in Python


#1
def knapsack(self,B,A,C,n):
    if n==0 or C==0:
        return 0
    if self.t[n][C]!=-1:
        return self.t[n][C]
    else:
        if B[n-1] <= C:
            self.t[n][C] = max(A[n-1]+ self.knapsack(B,A,C-B[n-1],n-1),self.knapsack(B,A,C,n-1))
            return self.t[n][C]
        else:
            self.t[n][C] = self.knapsack(B,A,C,n-1)
            return self.t[n][C]

def solve(self, A, B, C):
    n=len(A)
    self.t = [[-1 for i in range(C + 1)] for j in range(n + 1)]
    # print(self.t)
    return self.knapsack(B,A,C,n)

#2

same here. can someone point out the mistake .