My Solution
\n/**\n * the dynamic programming solution is employed.\n *\n * `dp[carpets][tiles]` stands for the minimum number of while tiles\n * when `carpets` carpets hav
```\n/**\n * the dynamic programming solution is employed.\n *\n * `dp[carpets][tiles]` stands for the minimum number of while tiles\n * when `carpets` carpets have been covered in the tile range [0, tiles),\n * 0 inclusive, `tiles` exclusive.\n * where `carpets` is in the range [0, `numCarpets`], both inclusive\n *       `tiles` is in the range [0, `floor.size()`], both inclusive\n *\n * initial:\n * if `carpets` == 0\n * 1. if tiles == 0,\n *    dp[carpets][tiles] = 0\n * 2. if tiles > 0,\n *    dp[carpets][tiles] = dp[carpets][tiles - 1] + (floor[tiles - 1] == \'1\' ? 1 : 0)\n *\n * induction:\n * 1. if tiles == 0\n *    dp[carpets][tiles] = 0\n * 2. otherwise\n * 2.1. let `covered` stand for the minimum number of while tiles\n *      if the `tiles - 1`\'th tile is covered by a carpet\n *      covered = dp[carpets - 1][max(0, tiles - carpetLen)]\n * 2.2. let `uncovered` stand for the minimum number of while tiles\n *      if the `tiles - 1`\'th tile is not covered by a carpet,\n *      uncovered = dp[carpets][tiles - 1] + (floor[tiles - 1] == \'1\' ? 1 : 0)\n * dp[carpets][tiles] = min(covered, uncovered)\n *\n * target:\n * dp[numCarpets][floor.size()]\n *\n * Time Complexity: O(numCarpets * n)\n * Space Complexity: O(n)\n * where `n` is the length of the string `floor`\n */\nclass Solution {\n public:\n  int minimumWhiteTiles(const string &floor, const int numCarpets, const int carpetLen) {\n    constexpr int range = 2;\n    constexpr char white = \'1\';\n    const int n = static_cast<int>(floor.size());\n    int dp[range][n + 1];\n    memset(dp, 0, sizeof(dp));\n    int previous = 0;\n    int current = 1;\n    for (int tiles = 1; tiles < n + 1; ++tiles) {\n      dp[previous][tiles] = dp[previous][tiles - 1] + (floor[tiles - 1] == white ? 1 : 0);\n    }\n    \n    for (int carpets = 1; carpets < numCarpets + 1; ++carpets) {\n      for (int tiles = 1; tiles < n + 1; ++tiles) {\n        const int covered = dp[previous][max(0, tiles - carpetLen)];\n        const int uncovered = dp[current][tiles - 1] + (floor[tiles - 1] == white ? 1 : 0);\n        dp[current][tiles] = min(covered, uncovered);\n      }\n      \n      previous ^= 1;\n      current ^= 1;\n      memset(dp[current], 0, sizeof(dp[current]));\n    }\n    \n    return dp[previous][n];\n  }\n};\n```
[]