Find the number of binary sequences of length such that for any two segments of of the same length, we have
- The sum of digits of differs from the sum of digits of by at most ;
- If begins on the left end of then the sum of digits of is not greater than the sum of digits of ;
- If ends on the right end of then the sum of digits of is not less than the sum of digits of .
, 2015
Solution
Note that if the sequence ends with zero then all digits of will be zero.
Now suppose that the sequence ends with one. Let be the number of 's in then . Let . We consider the sequence where if and only if .
One can check that this sequence has exactly ones and satisfies all the given conditions.
Now we need to prove that those are all possible sequences.
Suppose that is a sequence with exactly ones and also satisfying all the given conditions. We will show that we have only one possible arrangement for ones and zeros.
Let . Starting from the right, we will show that for any , among the first rightmost digits, there are exactly zeros.
It is clear that the statement holds for since the rightmost digit is a unit.
Suppose that the statement holds for . We consider two cases.
Case 1. If . We need to show that the rightmost digit of is zero. Otherwise, it follows that we have exactly in the rightmost digits and any consecutive digits, there are at most zeros. We divide the sequence from the right into segments of length and possibly one leftmost segment of length with .
The number of zeros is at most
which is a contradiction.
Case 2. If . We need to show that the rightmost digit of is a unit. Otherwise, it follows that for any consecutive digits, there are at least zeros. We divide the sequence from the right into segments of length and possibly one leftmost segment of length with . Note that in the first rightmost digits, we have exactly zeros. If in the leftmost segment of length we have then the number of zeros is at least
which is a contradiction.
We deduce that, in each segment of length we have exactly zeros. We divide the sequence into segments of length and possible one shorter segment from the left. Using the same argument as in the previous case, we do not have enough zeros, which is again a contradiction.
Therefore, the statement holds for all , which implies that for any , there exists a unique binary sequence with units satisfying the given conditions.