0
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ What do you mean by "are always positioned correctly"? It is possible to place them poorly and get stuck before covering $MN-1$ squares. But IIUC the question is about the maximum possible number of dominos (ie assuming they are placed optimally). $\endgroup$ – stewbasic Jun 9 '17 at 1:36
  • 2
    $\begingroup$ If $m$ is even, you can cover any column with $\frac{m}{2}$ copies of $2\times 1$ dominos completely. Similar things happen when $n$ is even. If both $m \times n$ is odd. For each column, cover the first $m-1$ cells by $\frac{m-1}{2}$ copies of $2 \times 1$ dominos. For the last row, cover the first $n-1$ cells by $\frac{n-1}{2}$ copies of $1 \times 2$ dominos. You are leave with a single cell. $\endgroup$ – achille hui Jun 9 '17 at 1:41
1
$\begingroup$

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$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.