Memory Limit exceed error


#1

Can anyone explain why my code is being shown a memory exceeded error ?

int dp[100007][3];
int count(int i,int j,vector<vector<int>>&A)
{
    if(i==A.size())
    {
        return 0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    
    
    return dp[i][j] = A[i][j]+min(count(i,(j+1)%3,A),count(i,(j+2)%3,A));
}

int Solution::solve(vector<vector<int> > &A) 
{
    int n=A.size();
    memset(dp,-1,sizeof(dp));
    
    int a = count(0,0,A);
    int b = count(0,1,A);
    int c = count(0,2,A);
    
    if (a <= b && a <= c)
        return a;
  
    else if (b <= a && b <= c)
        return b;
  
    else
        return c;
}