C++ DP Tabulation (row, col, neutralized)
Complexity

Time complexity: O(n∗m)


Space complexity: O(n∗m)

Code
# Complexity
- Time complexity: $O(n*m)$

- Space complexity: $O(n*m)$

# Code
```cpp []
#include <bits/stdc++.h>
using namespace std;

const vector<vector<int>> directions {{1, 0}, {0, 1}};
int dp[501][501][3];
class Solution {
public:
    int maximumAmount(vector<vector<int>>& coins) {
  		int n = coins.size(), m = coins[0].size();
  		for(int neutralized = 2; neutralized >= 0; neutralized--) {
  			for(int i = n-1; i >= 0; i--) {
  				for(int j = m-1; j >= 0; j--) {
  					if(i == n-1 && j == m-1) {
		  				if(neutralized < 2 && coins[i][j] < 0) dp[i][j][neutralized] = 0;
		  				else dp[i][j][neutralized] = coins[i][j];
		  			}else {
                        dp[i][j][neutralized] = INT_MIN;
    		  			for(const auto& dir : directions) {
    		  				int ni = i + dir[0], nj = j + dir[1];
    		  				if(0 <= ni && ni < n && 0 <= nj && nj < m) {
    		  					if(neutralized < 2 && coins[i][j] < 0) dp[i][j][neutralized] = max(dp[i][j][neutralized], dp[ni][nj][neutralized + 1]);
    		  					dp[i][j][neutralized] = max(dp[i][j][neutralized], coins[i][j] + dp[ni][nj][neutralized]);
    		  				}
    		  			}
                    }
  				}
  			}
  		}
  		return dp[0][0][0];
    }
};
```
['C++']