horizon wrote:
Let $n$ be a positive integer. Find the number of sequences $x_{1},x_{2},\ldots x_{2n-1},x_{2n}$, where $x_{i}\in\{-1,1\}$ for each $i$, satisfying the following condition: for any integer $k$ and $m$ such that $1\le k\le m\le n$ then the following inequality holds \[\left|\sum_{i=2k-1}^{2m}x_{i}\right|\le\ 2\]
We can consider the $2n$ numbers as being $n$ couples $(x_i,x_{i+1})$ with $i$ odd. Let $S_i=x_i+x_{i+1}$; then $S_i$ is $2$, $-2$ or $0$. If $S_i=2$ or $S_i=-2$, we have one way to choose $x_i,x_{i+1}$, while if $S_i=0$, we have two ways.
We can see that the form of the $n$ couples is $0,0,\ldots,0,2,0,\ldots,0,-2,0,\ldots,0,2,\ldots$.
Then we will choose $k$ positions for which $S_i =0$; there are $\binom {n} {k}2^k$ ways, and we have two ways to define the other $n-k$ sums, $2,-2,2,-2,\ldots$ or $-2,2,-2,2,\ldots$.
Thus the total number of sequences is $2\sum_{k=0}^{n-1} \binom {n}{k} 2^k + 2^n = 2\cdot 3^n-2^n$.