C++ | DP
Code
# Code
```cpp []
int n,m,dp[500][500][3] ,vis[500][500][3] ,id;
int rec(int i, int j ,int o ,vector<vector<int>>&coins){
    if(i == coins.size() || j == coins[0].size())return -1e7;
    if(i == coins.size() - 1 && j == coins[0].size()-1){
        if(o < 2)return max(0, coins[i][j]);
        else return coins[i][j];
    }

    int & ret = dp[i][j][o];
    if(vis[i][j][o] == id)return ret;
    vis[i][j][o] = id;

    ret = -1e7;
    if(o < 2)
        ret = max(rec(i + 1 , j ,o + 1 ,coins), rec(i, j + 1 , o + 1, coins));

    return ret = max(ret, coins[i][j] + max(rec(i + 1, j, o, coins) ,rec(i , j + 1, o, coins)));
}
class Solution {
public:
    int maximumAmount(vector<vector<int>>& coins) {
        id++;

        return rec(0 , 0 , 0, coins);
    }
};
```
['C++']