C++ || EASY TO UNDERSTAND || Memoization Code
\nclass Solution {\npublic:\n    int dp[1002][1002];\n    int solve(string &floor,int i,int n,int l,vector<int> &prefix)\n    {\n        if(i>=floor.size()||n==
```\nclass Solution {\npublic:\n    int dp[1002][1002];\n    int solve(string &floor,int i,int n,int l,vector<int> &prefix)\n    {\n        if(i>=floor.size()||n==0)\n        return 0;\n        if(dp[i][n]!=-1)\n        return dp[i][n];\n        if(floor[i]==\'0\')\n        return dp[i][n]=solve(floor,i+1,n,l,prefix);\n        int x=min((int)(floor.size()),(int)(i+l))-1;\n        int white=prefix[x];\n        if(i!=0)\n        white-=prefix[i-1];\n        int ans1=white+solve(floor,i+l,n-1,l,prefix);\n        int ans2=solve(floor,i+1,n,l,prefix);\n        return dp[i][n]=max(ans1,ans2);\n    }\n    int minimumWhiteTiles(string floor, int numCarpets, int carpetLen) {\n        int n=floor.size();\n        vector<int> prefix(n);\n        for(int i=0;i<=n;i++)\n        {\n            for(int j=0;j<=numCarpets;j++)\n            {\n                dp[i][j]=-1;\n            }\n        }\n        if(floor[0]==\'1\')\n        prefix[0]=1;\n        else\n        prefix[0]=0;\n        for(int i=1;i<n;i++)\n        {\n            prefix[i]=prefix[i-1]+(floor[i]==\'1\');\n        }\n        int total_white=prefix[n-1];\n        if(total_white==0)\n        return 0;\n        return total_white-solve(floor,0,numCarpets,carpetLen,prefix);\n    }\n};\n```\n**Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**
[]