rust 17ms solution with explaination
\n\n# Approach\nTo get the min exposed is to get the max covered;\n\nLet dp[n][i] be the max_covered with n carpets, let m be the length of carpets.\n\ndp[n][i]
![image.png](https://assets.leetcode.com/users/images/612f5345-e554-4d44-907d-20222a260dd6_1712773598.1896548.png)\n\n# Approach\nTo get the min exposed is to get the max covered;\n\nLet dp[n][i] be the max_covered with n carpets, let m be the length of carpets.\n\ndp[n][i]=max(\ndp[n-1][i-M]+cover[i-M+1] \\\\\\*I choose to cover from i-M+1 to i\\*\\\\,\nmax(dp[n][0 to i-1]) \\\\\\*max so far\\*\\\\)\n\n# Note\nDon\'t consider when the carpets overlap each other, that will not increase the white covered.\n\ndp[n][i] is all whites from 0 to i when i<M. I though when i<M\\*num_carpets is also correct, but this does not decrease the time needed.\n\n# Complexity\n- Time complexity:\n$$O(floor.len()*num\\_carpets)$$\n\n- Space complexity:\n$$O(floor.len())$$\n\n# Code\n```\nuse std::cmp::{min, max};\nuse std::mem::swap;\nimpl Solution {\n    pub fn minimum_white_tiles(floor: String, num_carpets: i32, carpet_len: i32) -> i32 {\n        if (num_carpets*carpet_len) as usize >= floor.len(){return 0;}\n        let carpet_len=carpet_len as usize;\n        let mut whites=0i32;\n        let floor=floor.as_bytes().iter().map(|&x|if x==b\'1\'{whites+=1;true}else{false}).collect::<Vec<bool>>();\n        if carpet_len==1{\n            return max(whites-num_carpets, 0);\n        }\n        if whites==0{return 0;}\n        \n        let mut cover=vec![0i32; floor.len()-carpet_len+1];\n        cover[0]=(0..carpet_len).filter(|x|floor[*x]).count() as i32;\n        for i in 1..cover.len(){\n            cover[i]=cover[i-1];\n            if floor[i+carpet_len-1]{cover[i]+=1;}\n            if floor[i-1]{cover[i]-=1;}\n        }\n\n        let mut sum=vec![0; carpet_len];\n        sum[0]=if floor[0]{1}else{0};\n        for i in 1..carpet_len{\n            sum[i]=sum[i-1];\n            if floor[i]{sum[i]+=1;}\n        }\n\n        let mut res=0;\n        let mut prev=vec![0i32; floor.len()];\n        let mut cur=vec![0i32; floor.len()];\n        for n in 1..=num_carpets{\n            let mut max_so_far=0;\n            for i in 0..floor.len(){\n                let c=if i<carpet_len{\n                    sum[i]\n                }else{\n                    prev[i-carpet_len]+cover[i-carpet_len+1]\n                };\n                max_so_far=max(max_so_far, c);\n                cur[i]=max_so_far;\n            }\n            swap(&mut cur,&mut  prev);\n        }\n        whites-prev[floor.len()-1]\n    }\n}\n```
['Dynamic Programming', 'Rust']