Skip to main content
OlympiadHQ

Browse · MathNet

Print

International Mathematical Olympiad

counting and probability

Problem

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 , where 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 . Replace the number in one of the cells with and erase the number in the other cell. At the end of the game, one cell contains the number , where 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 .
Solution
Solution 1. We will solve a more general problem, replacing the row of 9 cells with a row of cells, where is a positive integer. Denote by the maximum possible number of moves Sir Alex can make starting with a row of empty cells, and ending with one cell containing the number and all the other cells empty. Call an operation of type (1) an insertion, and an operation of type (2) a merge. Only one move is possible when , so we have . From now on we consider , 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 , and the other cells were empty. Paint one of those numbers blue, and the other one red. Now trace back Sir Alex's moves, always painting the numbers blue or red following this rule: if and merge into , paint and with the same color as . 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 involve 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 cells to produce one cell with the number and all the others empty, so there are at most 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 cells to produce one cell with the number and all the others empty, so there are at most red moves. This proves that On the other hand, we can start with an empty row of cells and perform moves to produce one cell with the number and all the others empty, and after that perform moves on those empty cells to produce the number in one of them, leaving empty. With one more merge we get one cell with and the others empty, proving that It follows that for and . If or , we must insert on our first move and immediately get the final configuration, so and , for and . These initial values, together with the recurrence relation (1), determine uniquely. Finally, we show that for all integers and . We use induction on . Since for , (2) is true for the base case. We make the induction hypothesis that (2) is true for some fixed positive integer and all . We have , and for the recurrence relation (1) and the induction hypothesis give us which completes the proof.

Solution 2. Define merges and insertions as in Solution 1. After each move made by Sir Alex we compute the number of empty cells, and the sum of all the numbers written in the cells. Insertions always increase by some power of 2, and increase exactly by 1. Merges do not change and decrease exactly by 1. Since the initial value of is 0 and its final value is 1, the total number of insertions exceeds that of merges by exactly one. So, to maximize the number of moves, we need to maximize the number of insertions. We will need the following lemma. Lemma. If the binary representation of a positive integer has nonzero digits, then cannot be represented as a sum of fewer than powers of 2. Moreover, any representation of as a sum of powers of 2 must coincide with its binary representation. Proof. Let be the minimum number of summands in all possible representations of as sum of powers of 2. Suppose there is such a representation with summands, where two of the summands are equal to each other. Then, replacing those two summands with the result of their sum, we obtain a representation with fewer than summands, which is a contradiction. We deduce that in any representation with summands, the summands are all distinct, so any such representation must coincide with the unique binary representation of , and . Now we split the solution into a sequence of claims. Claim 1. After every move, the number is the sum of at most distinct powers of 2. Proof. If is the sum of (or more) distinct powers of 2, the Lemma implies that the cells are filled with these numbers. This is a contradiction since no more merges or insertions can be made. Let denote the set of all positive integers not exceeding with at most nonzero digits in its base 2 representation. Since every insertion increases the value of , by Claim 1, the total number of insertions is at most . We proceed to prove that it is possible to achieve this number of insertions. Claim 2. Let , with . If after some of Sir Alex's moves the value of is , with , then there is a sequence of moves after which the value of is exactly . Proof. Suppose . Performing all possible merges, we eventually get different powers of 2 in all nonempty cells. After that, by Claim 1 there will be at least one empty cell, in which we want to insert . It remains to show that is a power of 2. For this purpose, we notice that if has less than nonzero digits in base 2 then . Otherwise, we have with . Then, adding any number less than to will result in a number with more than nonzero binary digits. On the other hand, is a sum of powers of 2, not all distinct, so by the Lemma it will be a sum of less than distinct powers of 2. This means that , completing the proof. Claims 1 and 2 prove that the maximum number of insertions is . We now compute this number. Claim 3. . Proof. The number is the only element of with binary digits. Any other element has at most binary digits, at least one and at most of them are nonzero (so they are ones). For each , there are such elements with exactly binary digits equal to one. We conclude that . Recalling that the number of insertions exceeds that of merges by exactly 1, we deduce that the maximum number of moves is .
Final answer
2 * sum_{j=0}^{8} C(n, j) - 1

Techniques

Invariants / monovariantsInduction / smoothingRecursion, bijectionAlgebraic properties of binomial coefficientsGames / greedy algorithms