# Maximum points by traversing from top left of Matrix to bottom right by two persons

#include using namespace std; const static int MAXR = 20, MAXC = 20;int cache[MAXC][MAXR][MAXC][MAXR], dp[MAXC][MAXR][MAXC][MAXR];int n, m;vector grid; int maxMoney(int x1, int y1, int x2, int y2){ if (x1 >= n || y1 >= m || x2 >= n || y2 >= m) return 0; if (cache[x1][y1][x2][y2] != 0) return dp[x1][y1][x2][y2]; cache[x1][y1][x2][y2] = 1; int money = grid[y1][x1] – ‘0’; if (x1 != x2 || y1 != y2) money += grid[y2][x2] – ‘0’; return dp[x1][y1][x2][y2] = money + max( max(maxMoney(x1 + 1, y1, x2 + 1, y2), maxMoney(x1, y1 + 1, x2 + 1, y2)), max(maxMoney(x1 + 1, y1, x2, y2 + 1), maxMoney(x1, y1 + 1, x2, y2 + 1)));} int32_t main(){ n = 3; m = 3; grid.push_back(“111”); grid.push_back(“101”); grid.push_back(“111”); cout