DP
We only need the previous state, so we can limit the size of our dp array to 2 * m.\n\nC++\ncpp\nint maxMoves(vector<vector<int>>& g) {\n    int m = g.size(), n
We only need the previous state, so we can limit the size of our `dp` array to `2 * m`.\n\n**C++**\n```cpp\nint maxMoves(vector<vector<int>>& g) {\n    int m = g.size(), n = g[0].size();\n    vector<vector<int>> dp(2, vector<int>(m));\n    for (int c = n - 2; c >= 0; --c)\n        for (int r = 0; r < m; ++r) {\n            int c0 = c % 2, c1 = (c + 1) % 2;\n            dp[c0][r] = g[r][c + 1] > g[r][c] ? 1 + dp[c1][r] : 0;\n            if (r > 0 && g[r - 1][c + 1] > g[r][c])\n                dp[c0][r] = max(dp[c0][r], 1 + dp[c1][r - 1]);\n            if (r + 1 < m && g[r + 1][c + 1] > g[r][c])\n                dp[c0][r] = max(dp[c0][r], 1 + dp[c1][r + 1]);\n        }\n    return *max_element(begin(dp[0]), end(dp[0]));\n}\n```
['C']