✅ C++ | DP + Memoization
\nclass Solution\n{\n    public:\n        int recur(string &s, int numCarpets, int len, int i, vector<vector < int>> &dp, vector< int > &sufOnes)\n        {\n  
```\nclass Solution\n{\n    public:\n        int recur(string &s, int numCarpets, int len, int i, vector<vector < int>> &dp, vector< int > &sufOnes)\n        {\n            if (i >= s.size())\n                return 0;\n            if (numCarpets == 0)\n                return sufOnes[i];\n\n            if (dp[i][numCarpets] != -1)\n            {\n                return dp[i][numCarpets];\n            }\n            if (s[i] == \'0\')\n            {\n                dp[i][numCarpets] = recur(s, numCarpets, len, i + 1, dp, sufOnes);\n            }\n            else\n            {\n               \t//start carpet here\n                int start = recur(s, numCarpets - 1, len, i + len, dp, sufOnes);\n               \t//dont start carpet here\n                int dont = 1 + recur(s, numCarpets, len, i + 1, dp, sufOnes);\n\n                dp[i][numCarpets] = min(start, dont);\n            }\n\n            return dp[i][numCarpets];\n        }\n    int minimumWhiteTiles(string s, int n, int len)\n    {\n        int nn = s.size() + 1, mm = n + 1;\n        vector<int> sufOnes(s.size() + 1, 0);\n        for (int i = s.size() - 1; i >= 0; i--)\n        {\n            sufOnes[i] = sufOnes[i + 1];\n            if (s[i] == \'1\')\n            {\n                sufOnes[i]++;\n            }\n        }\n        vector<vector < int>> dp(nn, vector<int> (mm, -1));\n        return recur(s, n, len, 0, dp, sufOnes);\n    }\n};\n```
['Memoization']