Maths Olympiad Prep

Library / HMMT February /837 of 1302

HMMT February, 2020

Combinatorics Difficulty 5.4 AIME, harder Find the answer United States

Problem:
A snake of length kk is an animal which occupies an ordered kk-tuple (s1,…,sk)(s_{1}, \ldots, s_{k}) of cells in a n×nn \times n grid of square unit cells. These cells must be pairwise distinct, and sis_{i} and si+1s_{i+1} must share a side for i=1,…,k−1i=1, \ldots, k-1. If the snake is currently occupying (s1,…,sk)(s_{1}, \ldots, s_{k}) and ss is an unoccupied cell sharing a side with s1s_{1}, the snake can move to occupy (s,s1,…,sk−1)(s, s_{1}, \ldots, s_{k-1}) instead.

Initially, a snake of length 4 is in the grid {1,2,…,30}2\{1,2, \ldots, 30\}^{2} occupying the positions (1,1),(1,2),(1,3),(1,4)(1,1),(1,2),(1,3),(1,4) with (1,1)(1,1) as its head. The snake repeatedly makes a move uniformly at random among moves it can legally make. Estimate NN, the expected number of moves the snake makes before it has no legal moves remaining.

An estimate of E>0E>0 will earn ⌊22min⁡(N/E,E/N)4⌋\left\lfloor 22 \min (N / E, E / N)^{4}\right\rfloor points.

A number or a short expression. Fractions can be typed as 3/2, and spacing doesn't matter.

Solution

Solution:
Let n=30n=30. The snake can get stuck in only 8 positions, while the total number of positions is about n2×4×3×3=36n2n^{2} \times 4 \times 3 \times 3=36 n^{2}. We can estimate the answer as 36n28=4050\frac{36 n^{2}}{8}=4050, which is good enough for 13 points.

Let's try to compute the answer as precisely as possible. For each head position (a,b)(a, b) and tail orientation c∈[0,36)c \in[0,36), let x=36(na+b)+cx=36(n a+b)+c be an integer denoting the current state of the snake. Let ExE_{x} by the expected number of moves the snake makes if it starts at state xx. If from state xx the snake can transition to any of states y1,y2,…,yky_{1}, y_{2}, \ldots, y_{k}, then add an equation of the form
Ex−1k∑i=1kEyi=1 E_{x}-\frac{1}{k} \sum_{i=1}^{k} E_{y_{i}}=1
Otherwise, if there are no transitions out of state xx then set Ex=0E_{x}=0.

It suffices to solve a system of 36n236 n^{2} linear equations for E0,E1,…,E36n2−1E_{0}, E_{1}, \ldots, E_{36 n^{2}-1}. Then the answer will equal EiE_{i}, where ii corresponds to the state described in the problem statement. Naively, using Gaussian elimination would require about (36n2)3≈3.4⋅1013\left(36 n^{2}\right)^{3} \approx 3.4 \cdot 10^{13} operations, which is too slow. Also, it will require too much memory to store (36n2)2\left(36 n^{2}\right)^{2} real numbers at once.

We can use the observation that initially, the maximum difference between any two indices within the same equation is at most ≈72n\approx 72 n, so Gaussian elimination only needs to perform approximately (36n2)⋅(72n)2≈1.5⋅1011\left(36 n^{2}\right) \cdot(72 n)^{2} \approx 1.5 \cdot 10^{11} operations. Furthermore, we'll only need to store ≈(36n2)⋅(72n)\approx\left(36 n^{2}\right) \cdot(72 n) real numbers at a time. Benjamin Qi's solution ends up finishing in less than two minutes for n=30n=30 (C++ code).

Want a route through all this instead of an archive? The track puts 2,604 problems in a working order, from Junior Challenge level to the IMO shortlist.

Source: MathNet, licensed CC-BY-4.0. Statement reproduced verbatim; metadata (topic, difficulty) added by this project.