Balanced String

Let S = { 1 , 1 } S= \{1, -1\} . A sequence ( a 1 , a 2 , , a n ) (a_1, a_2, \cdots , a_n) is called balanced if the following conditions hold:

  • a i S a_i \in S for all 1 i n 1 \leq i \leq n
  • Define S i = a 1 + a 2 + + a i S_i= a_1 + a_2 + \cdots + a_i . Then, S i 2 |S_i| \leq 2 for all 1 i n 1 \leq i \leq n .
  • Moreover, for all 1 i < j n 1 \leq i < j \leq n , we have S i S j 2 |S_i-S_j| \leq 2 .

Find the number of balanced sequences of length 2016 2016 (the number of balanced sequences with n = 2016 n=2016 ). Enter the last three digits of the answer.


The answer is 766.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

The condition is essentially saying that the absolute difference of the numbers of 1's and -1's in any contiguous subsequence doesn't exceed 2.

Call an index i i ( 1 i < n 1 \leq i < n ) repetitive if a i = a i + 1 a_i= a_{i+1} . Note that if we fix the set of repetitive indices, there are exactly two possibilities for the sequence (one starts with 1, the other starts with -1, and the remaining positions are filled with alternating 1's and -1's).

Now, note that the parity of all repetitive indices are same. To see why (let's say A=1 and B=-1), suppose we have two consecutive A's. Then, there must exist a pair of two consecutive B's between the next pair of consecutive A's, otherwise the substring is like ...AABABABAA..., which violates the condition (number of A's - number of B's > 2). Thus, the next repetitive index must be a B, and all B's are placed at an even distance from the first repetitive index.

If the parity of all repetitive indices are odd, we get 2 ( n 1 ) / 2 2^{\lceil (n-1)/2 \rceil} possibilities (just select a subset consisting entirely of odd numbers among the first n 1 n-1 natural numbers). Similarly, if the parity of all repetitive indices are even, we get 2 ( n 1 ) / 2 2^{\lfloor (n-1)/2 \rfloor} possibilities. Overall, the answer is 2 ( 2 ( n 1 ) / 2 + 2 ( n 1 ) / 2 1 ) 2 (2^{\lceil (n-1)/2 \rceil} + 2^{\lfloor (n-1)/2 \rfloor} -1) (-1 because we double count the empty set for both cases).

In this case, our answer is 2 ( 2 1007 + 2 1008 1 2(2^{1007} + 2^{1008} -1 ), which evaluates to 776 \boxed{776} modulo 1000.

I think this s is not quite right. There is, for example, the option that one starts with +1, then has alternating -1, +1, -1, ... and ends on +1, +1 (this leaves the series between 0 and 2, is thus allowed. There are several of these.

Here is my alternative: 1. there are three "corridors" for S_i, (i) between 0 and 2, (ii) between -1 and 1, (iii) between -2 and 0. Each of these corridors has (by the same argument as Sreejato's, 2^1008 possibilities (this is obvious for the middle corridor, the other two have 1007 alternating pairs + one "dangling +1 or -1).

Thus, the total should be 3 * 2^1008, which evaluates to 248 modulo 1000.

Susanne Yelin - 5 years, 11 months ago

Log in to reply

The sequence you mentioned corresponds to the set { n 1 } \{n-1\} of repetitive indices.

I'm not sure what you mean by "corridors"- could you explain?

Sreejato Bhattacharya - 5 years, 11 months ago

Log in to reply

By "corridors" I mean the following: the max S i and min S i cannot be more than 2 apart. That means that of the total of five options for any S_i, -2, -1, 0, 1, 2, only three consecutive ones can be used. Thus, the total series has to move either between 0 and 2, -1 and 1, or -2 and 0.

Susanne Yelin - 5 years, 11 months ago

Log in to reply

@Susanne Yelin I solved the problem in a similar way, but 3 * 2^1008 mod 1000 should evaluate to 768. Also, there are two double counted sequences: one where the max and min S_i are 1 and 0, and a sequence where they are 0 and -1. Because the max and min partial sums are only one apart, they fall under two different corridors. So we subtract 2 from our answer to get 766.

Dylan Young - 5 years, 11 months ago

Log in to reply

@Dylan Young I did the mod calculation by hand, so yes, there might be a mistake.

And also yes to the two double-counted sequences. I also figured this last night.

So, yes, I agree, it should be (3*2^1008 - 2) mod 1000.

Susanne Yelin - 5 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...