# | 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 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Name |
---|
Since the height of the corridor is five, the problem can be solved with a bitmask DP, where you would have as your states your current coordinate and the bitmask for the current column and the next column. You should traverse the corridor in the following manner: Place tatami at position (i, j) (if you haven't placed one beforehand) and then go to (i + 1, j). If i = 5, it means you have already completed that column and should proceed to (0, j + 1).
The bitmask would store which of the squares have already been occupied by tatamis. If your current square has already been occupied by a tatami, skip it. Otherwise, there are two ways to place it: Horizontally, occupying spots (i, j) and (i, j + 1) or Vertically, occupying (i, j) and (i + 1, j).
Say bits in positions [0, 4] will reference the current column and [5, 9] the next column. If you place a tatami horizontally, you should activate bits i and i + 5 to represent that those positions have been occupied. If you place it vertically, activate bits i and i + 1. Once your i coordinate has reached 5, the first 5 bits of the bitmask will no longer be relevant, since these such bits are a reference to the column that you have already passed by. In that case, you can do mask >>= 5 to shift the bits from [5, 9] to [0, 4].