[C++/Java] Memoization - Commented
Code\nC++ []\nclass Solution {\npublic:\n\n    #define WHITE \'1\'\n    \n    vector<vector<int>> dp;\n    int n, c;\n    \n    int solve(string &floor, int ind
## Code\n```C++ []\nclass Solution {\npublic:\n\n    #define WHITE \'1\'\n    \n    vector<vector<int>> dp;\n    int n, c;\n    \n    int solve(string &floor, int ind, int rem){\n\n        // Reached end - No white tiles visible\n        if(ind >= n) return 0;\n\n        // Checking cache\n        if(dp[ind][rem] != -1) return dp[ind][rem];\n\n        int res = 1e8;\n\n        // We have 2 options -> Cover this tile or don\'t\n        \n        // Don\'t cover this tile \n        // If its a white tile, one white tile is visible already\n        res = (floor[ind] == WHITE) + solve(floor, ind + 1, rem);\n        \n        // Cover this tile if its a white tile and carpets are still remaining\n        if(floor[ind] == WHITE and rem) res = min(res, solve(floor, ind + c, rem - 1));\n        \n        // Caching\n        return dp[ind][rem] = res;\n        \n    }\n    \n    int minimumWhiteTiles(string floor, int numCarpets, int carpetLen) {\n        n = floor.length(), c = carpetLen;\n\n        // 2D DP {index, carpetsRemaining}\n        dp = vector<vector<int>> (n + 1, vector<int> (numCarpets + 1, -1));\n\n        return solve(floor, 0, numCarpets);\n    }\n};\n```\n```Java []\nclass Solution {\n\n    private static final char WHITE = \'1\';\n    private int[][] dp;\n    private int n, c;\n\n    public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n        n = floor.length();\n        c = carpetLen;\n\n        // 2D DP {index, carpetsRemaining}\n        dp = new int[n + 1][numCarpets + 1];\n        for (int[] row : dp) {\n            Arrays.fill(row, -1);\n        }\n\n        return solve(floor, 0, numCarpets);\n    }\n\n    private int solve(String floor, int ind, int rem) {\n        // Reached end - No white tiles visible\n        if (ind >= n) {\n            return 0;\n        }\n\n        // Checking cache\n        if (dp[ind][rem] != -1) {\n            return dp[ind][rem];\n        }\n\n        int res = (int) 1e8;\n\n        // We have 2 options -> Cover this tile or don\'t\n\n        // Don\'t cover this tile\n        // If it\'s a white tile, one white tile is visible already\n        res = (floor.charAt(ind) == WHITE ? 1 : 0) + solve(floor, ind + 1, rem);\n\n        // Cover this tile if it\'s a white tile and carpets are still remaining\n        if (floor.charAt(ind) == WHITE && rem > 0) {\n            res = Math.min(res, solve(floor, ind + c, rem - 1));\n        }\n\n        // Caching\n        dp[ind][rem] = res;\n        return res;\n    }\n}\n\n```\n\n## Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->
['Memoization', 'C++', 'Java']