C++ | DP | Bottom Up Dp | Similar to Knapsack
Please upvote\n\nclass Solution {\npublic:\n    int minimumWhiteTiles(string floor, int numCarpets, int len) {\n        int n=floor.size();\n        int x=numCa
Please upvote\n```\nclass Solution {\npublic:\n    int minimumWhiteTiles(string floor, int numCarpets, int len) {\n        int n=floor.size();\n        int x=numCarpets;\n        floor=\'#\'+floor;//so that ith row of dp matches with the ith character\n        vector<vector<int>> dp(n+1,vector<int>(x+1,0));\n        dp[0][0]=0;\n        for(int i=0;i<=x;i++){\n            dp[0][i]=0;\n        }\n        for(int i=1;i<=n;i++){\n            dp[i][0]=dp[i-1][0]+(floor[i]==\'1\');\n        }\n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=x;j++){\n                if(j>=1){\n\t\t\t\t//if we have atleast 1 carpet or even more\n\t\t\t\t//then we can use\n\t\t\t\t//however before usuing at i also check if i-len>=0\n                    if(i-len>=0){\n                        dp[i][j]=min(dp[i-len][j-1],dp[i-1][j]+(floor[i]==\'1\'));\n                    }\n                }\n                else{\n\t\t\t\t//if we do not have any carpet\n                    dp[i][j]=dp[i-1][j]+(floor[i]==\'1\');\n                }\n            }\n        }\n        return dp[n][x];\n    }\n};\n```
[]