easy c++ solution |dp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool fun(int i, int j, vector<vector<int>>& grid, int health, vector<vector<vector<int>>>& dp,vector<vector<int>>&visited) {\n        if (i == grid.size() - 1 && j == grid[0].size() - 1) {\n            return health >= 1;\n        }\n\n        if (dp[i][j][health] != -1) {\n            return dp[i][j][health];\n        }\n\n        int row[4] = {0, -1, 0, 1};\n        int col[4] = {1, 0, -1, 0};\n        bool ans = false;\n\n        for (int k = 0; k < 4; k++) {\n            int nrow = i + row[k];\n            int ncol = j + col[k];\n\n            if (nrow >= 0 && nrow < grid.size() && ncol >= 0 && ncol < grid[0].size() && visited[nrow][ncol]!=1) {\n                visited[nrow][ncol]=1;\n                if (grid[nrow][ncol] == 0) {\n                    bool curr = fun(nrow, ncol, grid, health, dp,visited);\n                    if (curr) ans = true;\n                } else if (grid[nrow][ncol] == 1 && health > 1) {\n                    bool curr = fun(nrow, ncol, grid, health - 1, dp,visited);\n                    if (curr) ans = true;\n                }\n                visited[nrow][ncol]=0;\n            }\n        }\n        return dp[i][j][health] = ans;\n    }\n\n    bool findSafeWalk(vector<vector<int>>& grid, int health) {\n        if(grid[0][0]==1){\n            health--;\n        }\n        vector<vector<vector<int>>> dp(grid.size(), vector<vector<int>>(grid[0].size(), vector<int>(health + 1, -1)));\n        vector<vector<int>>visited(grid.size(),vector<int>(grid[0].size(),0));\n        return fun(0, 0, grid, health, dp,visited);\n    }\n};\n\n```
['C++']