Memoization | 3D DP |  Striver Based approach | T.C=(MxN )  S.C=(MxN)
EditInitialize your DP with -1e8 or (less than -1e3) because -1 could be
the possible solution in pathIntuitionApproachIn dp either you go top down(Memoization)

# **Edit**
Initialize your DP with -1e8 or (less than -1e3) because -1 could be 
the possible solution in path 
# Intuition
<!-- -->After reading problem i realised this is dp question because i had done similar type question earlier  

# Approach
<!-- Describe your approach to solving the problem. -->
In dp either you go top down(Memoization) or bottom up(Tabulation)
I did this with Memo.. starting from index (m-1,n-1 )
Now i explore all path if coins>=0 else coins<0   
Also you have to maintain count variable so 3d dp i used  
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(M*N)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(M*N)

# Code
```cpp []
class Solution {
public:
int solve(int row,int col,   vector<vector<vector<int>>>&dp,vector<vector<int>>& coins,int count)
{
    if(row==0 && col==0)
    {
        if(coins[row][col]>=0)
        {
            return coins[row][col];
        }
        else
        {
            if(count>0)
            {
               return  0;
            }
            else
            {
                return coins[row][col];
            }
        }
    }
    if(row<0 || col<0 )
    {
        return -1e8;
    }
    if(dp[row][col][count]!=-1e8)
    {
        return dp[row][col][count];
    }
    int up=0,left=0;
    int ans=0;
    if(coins[row][col]<0)
    {
        if(count>0)
        {
            int notneutralize=coins[row][col];  //either not neutralize
              up=solve(row-1,col,dp,coins,count);
            left=solve(row,col-1,dp,coins,count);


            int neutralize=0;                         //or neutralize
              int up1=solve(row-1,col,dp,coins,count-1);
              int  left1=solve(row,col-1,dp,coins,count-1);


            ans=max(notneutralize+max(up,left),max(up1,left1));
        }
        else
        {
            int notneutralize=coins[row][col];  //either not neutralize
              up=solve(row-1,col,dp,coins,count);
            left=solve(row,col-1,dp,coins,count);
             ans=notneutralize+max(up,left);
        }
         dp[row][col][count]=ans;
    }
    if(coins[row][col]>=0)
    {
         up=solve(row-1,col,dp,coins,count);
         left=solve(row,col-1,dp,coins,count);
          dp[row][col][count]=coins[row][col]+max(up,left);
    }
    return dp[row][col][count];
}
    int maximumAmount(vector<vector<int>>& coins) {
        int m=coins.size();
        int n=coins[0].size();
        vector<vector<vector<int>>>dp(m,vector<vector<int>>(n,vector<int>(3,-1e8)));
        return solve(m-1,n-1,dp,coins,2);

    }
};
```
['Dynamic Programming', 'Memoization', 'C++']