Let $Z\left(n,m\right)$ be the number of unique binary strings of length $m$ containing at least one instance of $n$ consecutive 1's. I am trying to come up with an expression for $Z$, preferably directly calculable though I will accept a recursive solution as well. I have attempted a formulation based on [1], $$ \hat{Z}\left(n,m\right) = \sum_{q=m}^{n}\sum_{i=1}^{\lfloor \frac{q}{m}\rfloor}(-1)^{i+1}\binom{n-q+1}{i}\binom{n-mi}{n-q}\text{,}$$ however I am getting some discrepencies against test cases I worked out by hand. For example, it works for $Z\left(7,6\right)=3$ and $Z\left(7,5\right)=8$, but it does not work for $\left(7,4\right)=16$ (the formulation above gives $20$). N.B.: my definitions of $n$ and $m$ are opposite those of [1]; $q$ is the same.
I believe it has something to do with double-counting some string permutations, but I haven't been able to work out what else I have to take out.
Update: I found a recursive formulation [2] that gives me the same result as my $\hat{Z}$ above: $$ \tilde{Z}\left(n,m\right) = 2\tilde{Z}\left(n-1,m\right) + 2^{n-m-1}-\tilde{Z}\left(n-m-1,m\right) $$ Having found this independent formulation, I will have to revisit my counting and see if I've made a mistake somewhere.
Bonus points for an answer that works for arbitrary dictionaries, i.e. $W\left(a,n,m\right)$ where $a$ is the number of possible symbols in each position of the string. The original question would be equivalent to $Z\left(n,m\right) = W\left(2,n,m\right)$.
- [1] G.L., Number of binary strings containing at least n consecutive 1
- [2] Gerry Myerson, response to Number of bit strings with 3 consecutive zeros or 4 consecutive 1s