[c++] | DP Solution | Memoization | (100% FAST) | EASY TO UNDERSTAND
\nclass Solution {\npublic:\n    int solve(vector<int> &hash, int &num, int &len, int i, int j, vector<vector<int>> &dp){\n        int n = hash.size();\n       
```\nclass Solution {\npublic:\n    int solve(vector<int> &hash, int &num, int &len, int i, int j, vector<vector<int>> &dp){\n        int n = hash.size();\n        if (j >= num or i >= n)  return 0;\n        if (dp[i][j] != -1) return dp[i][j];\n//     Dont want to put the carpet on the ith place\n        int not_take = solve(hash, num, len, i+1, j, dp);\n//     Want to put the carpet on the ith place and the corresponding value which it gives is added\n        int take = hash[i] + solve(hash, num, len, i+len, j+1, dp);\n        \n        return dp[i][j] = max(not_take, take);\n    }\n    \n    int minimumWhiteTiles(string floor, int num, int len) {\n        int n = floor.size();\n        if (num*len >= n)   return 0;    \n        int var = 0, count = 0;\n        for (int i = 0;i < n;i++)   count += (floor[i] == \'1\');\n        if (count == n){\n            return (n - (num*len));\n        }\n//     hash stores that if we put the carpet at the ith position \n//     then how much white space i\'ll cover\n        vector<int> hash(n);\n        for (int i = n-1;i >= 0;i--){\n            if (floor[i] == \'1\'){\n                var += 1;\n            }\n            if (i+len < n and floor[i+len] == \'1\'){\n                var -= 1;\n            }\n            hash[i] = var;\n        }\n//     dp[i][j] stores if i am on the ith index and jth carpet is used \n//     then how much maximum white spaces i\'ll cover\n        vector<vector<int>> dp(n, vector<int> (num, -1));\n//     solve gives me the maximus white i can cover with carpet using the num number of carpets \n//     of length len\n        int temp = solve(hash, num, len, 0, 0, dp);\n        return count - temp;\n    }\n};\n```\nComment below if you have any doubt\nPlease upvote if you like\n
['Dynamic Programming', 'Memoization']