Subfield: Combinatorics


Question: Sir Alex plays the following game on a row of 9 cells. Initially, all cells are empty. In each move, Sir Alex is allowed to perform exactly one of the following two operations:

(1) Choose any number of the form $2^{j}$, where $j$ is a non-negative integer, and put it into an empty cell.

(2) Choose two (not necessarily adjacent) cells with the same number in them; denote that number by $2^{j}$. Replace the number in one of the cells with $2^{j+1}$ and erase the number in the other cell.

At the end of the game, one cell contains the number $2^{n}$, where $n$ is a given positive integer, while the other cells are empty. Determine the maximum number of moves that Sir Alex could have made, in terms of $n$.

Solution:
We will solve a more general problem, replacing the row of 9 cells with a row of $k$ cells, where $k$ is a positive integer. Denote by $m(n, k)$ the maximum possible number of moves Sir Alex can make starting with a row of $k$ empty cells, and ending with one cell containing the number $2^{n}$ and all the other $k-1$ cells empty. Call an operation of type (1) an insertion, and an operation of type (2) a merge.

Only one move is possible when $k=1$, so we have $m(n, 1)=1$. From now on we consider $k \geqslant 2$, and we may assume Sir Alex's last move was a merge. Then, just before the last move, there were exactly two cells with the number $2^{n-1}$, and the other $k-2$ cells were empty.

Paint one of those numbers $2^{n-1}$ blue, and the other one red. Now trace back Sir Alex's moves, always painting the numbers blue or red following this rule: if $a$ and $b$ merge into $c$, paint $a$ and $b$ with the same color as $c$. Notice that in this backward process new numbers are produced only by reversing merges, since reversing an insertion simply means deleting one of the numbers. Therefore, all numbers appearing in the whole process will receive one of the two colors.

Sir Alex's first move is an insertion. Without loss of generality, assume this first number inserted is blue. Then, from this point on, until the last move, there is always at least one cell with a blue number.

Besides the last move, there is no move involving a blue and a red number, since all merges involves numbers with the same color, and insertions involve only one number. Call an insertion of a blue number or merge of two blue numbers a blue move, and define a red move analogously.

The whole sequence of blue moves could be repeated on another row of $k$ cells to produce one cell with the number $2^{n-1}$ and all the others empty, so there are at most $m(n-1, k)$ blue moves.

Now we look at the red moves. Since every time we perform a red move there is at least one cell occupied with a blue number, the whole sequence of red moves could be repeated on a row of $k-1$ cells to produce one cell with the number $2^{n-1}$ and all the others empty, so there are at most $m(n-1, k-1)$ red moves. This proves that

$$
m(n, k) \leqslant m(n-1, k)+m(n-1, k-1)+1 .
$$

On the other hand, we can start with an empty row of $k$ cells and perform $m(n-1, k)$ moves to produce one cell with the number $2^{n-1}$ and all the others empty, and after that perform $m(n-1, k-1)$ moves on those $k-1$ empty cells to produce the number $2^{n-1}$ in one of them, leaving $k-2$ empty. With one more merge we get one cell with $2^{n}$ and the others empty, proving that

$$
m(n, k) \geqslant m(n-1, k)+m(n-1, k-1)+1 .
$$



It follows that

$$
m(n, k)=m(n-1, k)+m(n-1, k-1)+1
\tag{1}
$$

for $n \geqslant 1$ and $k \geqslant 2$.

If $k=1$ or $n=0$, we must insert $2^{n}$ on our first move and immediately get the final configuration, so $m(0, k)=1$ and $m(n, 1)=1$, for $n \geqslant 0$ and $k \geqslant 1$. These initial values, together with the recurrence relation (1), determine $m(n, k)$ uniquely.

Finally, we show that

$$
m(n, k)=2 \sum_{j=0}^{k-1}\left(\begin{array}{l}
n \\
j
\end{array}\right)-1
\tag{2}
$$

for all integers $n \geqslant 0$ and $k \geqslant 1$.

We use induction on $n$. Since $m(0, k)=1$ for $k \geqslant 1,(2)$ is true for the base case. We make the induction hypothesis that (2) is true for some fixed positive integer $n$ and all $k \geqslant 1$. We have $m(n+1,1)=1=2\left(\begin{array}{c}n+1 \\ 0\end{array}\right)-1$, and for $k \geqslant 2$ the recurrence relation (1) and the induction hypothesis give us

$$
\begin{aligned}
& m(n+1, k)=m(n, k)+m(n, k-1)+1=2 \sum_{j=0}^{k-1}\left(\begin{array}{c}
n \\
j
\end{array}\right)-1+2 \sum_{j=0}^{k-2}\left(\begin{array}{l}
n \\
j
\end{array}\right)-1+1 \\
& \quad=2 \sum_{j=0}^{k-1}\left(\begin{array}{c}
n \\
j
\end{array}\right)+2 \sum_{j=0}^{k-1}\left(\begin{array}{c}
n \\
j-1
\end{array}\right)-1=2 \sum_{j=0}^{k-1}\left(\left(\begin{array}{c}
n \\
j
\end{array}\right)+\left(\begin{array}{c}
n \\
j-1
\end{array}\right)\right)-1=2 \sum_{j=0}^{k-1}\left(\begin{array}{c}
n+1 \\
j
\end{array}\right)-1,
\end{aligned}
$$

which completes the proof.

Final answer: $2 \sum_{j=0}^{8}\left(\begin{array}{c}n \\ j\end{array}\right)-1$