How to solve this problem?
Problem
I thought the solution was simple at first, but it turned out to be too complicated for me.
The tricky part is this test (thanks to puravjn for the test):
6
......
....#.
.#####
.#.#..
......
......
How to solve this problem?
You are given an $$$n \times n$$$ board with some squares removed.
Determine whether it is possible to completely cover all remaining squares with $$$2 \times 1$$$ dominoes, without overlaps and without covering any removed squares.
Note: Each of the dominoes can cover a black cell and a white cell if they are next to each other
Output "YES" if such a covering exists, otherwise output "NO".
$$$n \leq 50$$$
I thought the solution was simple at first, but it turned out to be too complicated for me.
The tricky part is this test (thanks to puravjn for the test):
6
......
....#.
.#####
.#.#..
......
......
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 3 | Proof_by_QED | 147 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Название |
|---|



Auto comment: topic has been updated by Mitpro (previous revision, new revision, compare).
First of all, can you solve the problem for a complete square board of size $$$n*n$$$ (without any squares removed) ?
Then, to which types/shapes of boards (maybe not squares) can you transpose this approach ?
Finally, how to link these results with you problem input ?
convert the problem to a graph
use greedy (selecting two connected vertices and continuing with another one)
you might need to try the root for everyone
the solution is not 100% correct (in that case i apologize)
If there are an odd number of squares it's clearly impossible. Loop over all squares till you find a square $$$u$$$ with degree $$$d \lt 2$$$. If $$$d=0$$$ the square is blocked on all sides so clearly impossible. If $$$d=1$$$, if a solution exists it must have a domino at $$$s$$$ and it's neighbor. Adding this domino may cause other squares to have degree 1, so DFS squares adjacent to the added domino till all squares are degree > 1. If at any point we create surround a square on all sides or cause a self-intersection it's impossible.
If it's possible to DFS till all squares have degree $$$d \gt 1$$$, (I think) It's possible to tile the whole grid, so we're done.
I spent way too long trying to prove this fact. If anyone has a counterexample pls lmk
just build a bipartite graph with one part being the white cells and second part being the black cells, each domino covers 1 black and 1 white cell so if cntblack != cntwhite then answer is NO either way you run a maximum matching algorithm on this graph and print yes if maximum_matching == cnt_black (doesnt matter which since they are equal) and that is it. there is also a dp approach using profile dp
Bruh, that's my problem K in my Div. 4 contest, I know the solution now
But thanks for showing me