Kindly try this problem and provide a detailed algorithm for solving it, i will be extremely thankfull. Link to the problem Edit-Seems to be extremely strange, that people rather than helping are delibrately downvoting just for the sake of fun.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Kindly try this problem and provide a detailed algorithm for solving it, i will be extremely thankfull. Link to the problem Edit-Seems to be extremely strange, that people rather than helping are delibrately downvoting just for the sake of fun.
Name |
---|
Auto comment: topic has been updated by padfoot1717 (previous revision, new revision, compare).
Consider the one-dimensional version of this problem(i.e., h = 1) . Here you can see that a greedy solution would work where you'll make a cut only when the number of 1's in the current segment exceeds k.
Coming to the original problem, since h <= 10 thus you could brute force the number of horizontal cuts(i.e., try every possible combination of horizontal cuts) and for each combination calculate greedily the number of vertical cuts required to ensure that each component has <= k 1's (just like the one-dimensional counterpart of this problem).
Thanks.
Can you please further elaborate that after chosing a particular combination of horizontal cuts, how am i going to decide greedily where to make vertical cuts.
Just like in the one-dimensional counterpart we can use prefix sums here. Simply create the prefix sums for every row. For checking whether a vertical cut is required at the current position we can simply check the maximum number of chocolates that are present at any of the blocks enclosed between the previous vertical cut(or the left boundary in case no cut has been made) and the current position which we are considering.
Coming to the part where you need to check the maximum, consider its 1-D counterpart where you are given a boolean array and the positions where it is partitioned. To find the maximum number of 1s in this case, the most trivial way is to check for each segment(brute force). Coming back to the problem since h <= 10 brute force can also work here. However, instead of blindly checking for each segment we can use prefix sums to reduce the complexity of this task from O(hw) to O(h),
Ok, i got it.