C++ Solution || Memoization Approach || Easy to Understand
Intuition\nThe problem can be visualized as finding the longest increasing path in a grid that moves strictly rightward (from left to right) and does not revisi
# Intuition\nThe problem can be visualized as finding the longest increasing path in a grid that moves strictly rightward (from left to right) and does not revisit a smaller or equal value. Starting from any cell in the leftmost column, we aim to reach the rightmost column, maximizing the number of moves along the way.\n\n# Approach\n1. **DFS with Memoization**:\n    - For each cell in the leftmost column, initiate a depth-first search (DFS) that explores potential paths toward the right, only moving to cells with strictly greater values.\n2. **Memoization**:\n    -  Use a `dp` array to store the maximum number of moves possible from each cell, avoiding redundant computations.\n3. **Recursive Conditions**:\n    - Move to the right, right-up, or right-down if the next cell has a greater value.\n    - Return `0` if the move would go out of bounds or if the next cell\'s value is not strictly increasing.\n5. **Result**: \n    - The final answer is the maximum of all DFS results from each cell in the leftmost column, minus 1 (since we\'re counting moves, not cells).\n\n# Complexity\n- Time complexity: $$O(n*m)$$\n\n- Space complexity: $$O(n*m)$$ \n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int dfs(int i, int j, int prev, vector<vector<int>>& grid,\n            vector<vector<int>>& dp) {\n        int n = grid.size();\n        int m = grid[0].size();\n        if (i < 0 || j < 0 || i >= n || j >= m)\n            return 0;\n        if (dp[i][j] != -1)\n            return dp[i][j];\n        int val = grid[i][j];\n        if (val <= prev)\n            return 0;\n        return dp[i][j] = 1 + max({dfs(i - 1, j + 1, val, grid, dp),\n                                   dfs(i, j + 1, val, grid, dp),\n                                   dfs(i + 1, j + 1, val, grid, dp)});\n    }\n    int maxMoves(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        vector<vector<int>> dp(n, vector<int>(m, -1));\n        int ans = 0;\n        for (int i = 0; i < n; i++)\n            ans = max(ans, dfs(i, 0, -1, grid, dp));\n        return ans - 1;\n    }\n};\n\n```\n\n# Quote of the Day\n> ***Success is the result of exploring every possibility while keeping track of your achievements.***\n\n\n![1721315779911.jpeg](https://assets.leetcode.com/users/images/f4194ce5-e45b-4ee4-bc7e-db1f16a408db_1730194807.0759444.jpeg)\n
['Array', 'Dynamic Programming', 'Matrix', 'C++']