Two same solution one is working others is not
IntuitionDifference is In first solution, I initialize the DP dynamica
and In the second one static.Kindly anybody help, why this is happeningCode
# Intuition
Difference is In first solution, I initialize the DP dynamica
and In the second one static.

Kindly anybody help, why this is happening

# Code
```cpp []
class Solution {
public:
    int recur(int x, int y, int row, int col, int chance,vector<vector<int>>& coins, vector<vector<vector<int>>>&dp) {
        if((x == row-1 && y == col-1)) {
            if(coins[x][y] < 0 && chance > 0)  return 0;
            return coins[x][y];
        }
        if(x>=row || y>=row)    return -999999;
        if(dp[x][y][chance] != -999999)  return dp[x][y][chance];
        int t1 = -999999, t2 = -999999;
        if(coins[x][y] < 0 && chance > 0){
            t1 =  max(recur(x+1, y, row, col, chance-1, coins, dp),
            recur(x, y+1, row, col, chance-1, coins, dp));
        }
        t2 =  coins[x][y] + max(recur(x+1, y, row, col, chance, coins, dp), 
        recur(x, y+1, row, col, chance, coins, dp));
        return dp[x][y][chance] =  max({t1, t2});
    }

    int maximumAmount(vector<vector<int>>& coins) {
        int n = coins.size();
        int m = coins[0].size();
        vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(m+1, vector<int>(3, -999999)));
        return recur(0, 0, n, m, 2, coins, dp);
    }
};


```



```
class Solution {
public:
    int dp[501][501][3];
    int recur(int x, int y, int row, int col, int chance,vector<vector<int>>& coins) {
        if((x == row-1 && y == col-1)) {
            if(coins[x][y] < 0 && chance > 0)  return 0;
            return coins[x][y];
        }
        if(x>=row || y>=row)    return -999999;
        if(dp[x][y][chance] != -1)  return dp[x][y][chance];
        int t1 = -999999, t2 = -999999;
        if(coins[x][y] < 0 && chance > 0){
            t1 =  max(recur(x+1, y, row, col, chance-1, coins),
            recur(x, y+1, row, col, chance-1, coins));
        }
        t2 =  coins[x][y] + max(recur(x+1, y, row, col, chance, coins), 
        recur(x, y+1, row, col, chance, coins));
        return dp[x][y][chance] =  max({t1, t2});
    }

    int maximumAmount(vector<vector<int>>& coins) {
        int row = coins.size();
        int col = coins[0].size();
        memset(dp, -1, sizeof(dp));
        return recur(0, 0, row, col, 2, coins);
    }
};
```
['C++']