[Math] Maximum number of 2 by 1 dominoes to tile rectangle

combinatorics

I found this problem on codeforces.

You are given a rectangular board of $M \times N$ squares. Also you are given an unlimited number of standard domino pieces of $2 \times 1$ squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:

  1. Each domino completely covers two squares.

  2. No two dominoes overlap.

  3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.

Find the maximum number of dominoes which can be placed under these restrictions.

The answer is $\left\lfloor \frac{MN}{2}\right\rfloor$. Why is this always the case? I don't "see" why the dominoes somehow are always positioned correctly.

Best Answer

If $N$ is even, then place $M$ rows of $\frac{N}{2}$ dominoes and cover the whole board.
Else if $N$ is odd, then cover $N-1$ rows of the board and put $\left \lfloor \frac{M}{2} \right \rfloor$ dominoes on the last row. If both $N$ and $M$ are odd, one cell remains uncovered.
That's how you get $\left\lfloor \frac{MN}{2}\right\rfloor$.