DP✅ | C++ | Beginner friendly💯
Approachdp[i][j][k] = maximum coins you can earn from i,j to n-1,m-1 given you can still neutralise k robbersComplexity
Time complexity: O(N*M)

Space complexit


# Approach
dp[i][j][k] = maximum coins you can earn from i,j to n-1,m-1 given you can still neutralise k robbers
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(N*M)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
#define ll long long
class Solution {
public:
    int maximumAmount(vector<vector<int>>& c) {
        int n = c.size();
        int m = c[0].size();
        ll dp[501][501][3];
        for(int i=0; i<=500; i++){
            for(int j=0; j<=500; j++){
                for(int k=0; k<=2; k++){
                    dp[i][j][k] = -1e12; 
                }
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            for (int j = m - 1; j >= 0; j--) {
                if (i == n - 1 && j == m - 1) {
                    dp[i][j][0] = c[i][j];
                    for(int k=1; k<=2; k++){
                        dp[i][j][k] = max(0, c[i][j]); 
                    }
                    continue;
                }
                dp[i][j][0] = c[i][j] + max(dp[i + 1][j][0], dp[i][j + 1][0]);
                for(int k=1; k<=2; k++){
                    dp[i][j][k] = c[i][j] + max(dp[i + 1][j][k], dp[i][j + 1][k]);
                    dp[i][j][k] = max(dp[i][j][k], max(dp[i + 1][j][k - 1], dp[i][j + 1][k - 1]));
                }
            }
        }
        return dp[0][0][2];
    }
};
```
['C++']