A sequence of non-negative integers is given. There's also a sequence of consecutive cells enumerated from to from left to right, such that initially the number is written on the -th cell, for . Starting from this initial position, we repeat the following sequence of steps, as long as it's possible:
Step 1: Add up the numbers written on all the cells, denote the sum as .
Step 2: If is equal to or if it is larger than the current number of cells, the process terminates. Otherwise, remove the -th cell, and shift all cells that are to the right of it one position to the left. Then go to Step 1.
Example: .
A sequence of non-negative integers is called balanced, if at the end of this process there's exactly one cell left, and it's the cell that was initially enumerated by , i.e. the cell that was initially in the middle.
Find the total number of balanced sequences as a function of .
Solution
The answer is: , where is the -th Catalan number.
We divide the proof into several steps. First, some terminology: the last (rightmost) cells will be called the back cells and the front (leftmost) cells will be called the front cells. The central, -st, cell will be called the middle cell.
Claim 1. All the back cells must be removed before any front cell is removed.
Proof. Assume for contradiction that this is not the case. Then there must be a point in time where a front cell is deleted and then immediately after a back cell is deleted. Let us say that the deleted front cell was at position . So all back cells have positions greater or equal to . After the cell is deleted all back cells have positions greater or equal to . But since we deleted cell , then the total sum is and this does not increase. So at the next step we delete a cell at position at most , a contradiction.
Claim 2. The middle cell must contain the number , i.e., .
Proof. Consider the last step in the process where we have total of cells. One of these is the middle cell, and by Claim 1 the other must be one of the front cells. I.e. we have . On the next move, we remove , which means that . So or . But after that we cannot remove , which means that . So .
Now, let's define a self-destructing sequence to be one with no surviving cells at the end of the process. For example, is self-destructing because . Let be the set of self-destructing sequences of length . For example, . It is clear that the front cells form a self-destructing sequence, i.e., . The back cells also have certain self-destructing quality, which is made more precise in Claim 3 below.
Claim 3. Fix the front sequence . Let be the set of all possible back sequences of length that can be appended to (with a between them) to get a balanced sequence. Then there is a bijection .
Proof. Let and consider a particular . Let be the initial index of the last surviving cell in . Then defines a bijection .
Indeed we claim that the -th deleted cell in is the -th deleted cell in for each . Indeed after some deletions let be the total sum remaining in . Then the total sum remaining in is . So we delete next the cell in position in if and only if we delete the cell in position in .
So is clearly a balanced sequence: we first eliminate all cells in the back, then the front. In the same manner it follows that every balanced sequence is of this form.
So far we have shown that the total number of balanced sequences is . It remains to calculate the size .
Claim 4. Let be the set of -sequences consisting of zeros and ones such that in each initial segment the number of 's does not surpass the number of 's. Then .
Proof. Let , and let us also consider the set of non-decreasing mappings such that for each . The claim will follow once we show that and that .
In order to demonstrate that , observe that there is an obvious bijective correspondence between the sets and . Indeed, reversing the self-destructing process for an -sequence , simply define to be the (partial) sum of the existing terms after the -th backward step.
As for , note the following bijective correspondence between the sets and . Let equal , where is defined to be the total number of 's appearing in before the -th zero.
Finally, it is a known fact that is the -th Catalan number . (The essential idea of the textbook proof of this fact uses the so-called reflection principle of A. D. André.)