TITLE: Number of q-ary strings of length m which do not contain k consecutive zeros
QUESTION [5 upvotes]: A finite q-ary-alphabet is given $$A_q = {0,1,2,...,q-1}.$$ Now I am considering the set of all finite strings over the alphabet $A_q$.
I am interested on the number $$N(m,k)_{A_q}$$ of strings of length $m$ which do not contain $k$ consecutive zeros. Is there a general formulary for this number? Or how can I determine $N(m,k)_{A_q}$?

REPLY [2 votes]: Based on Markus Scheuer's answer, I tried to derive a general formula for the asked number. The number of $q$-ary strings of length $m$ with no $k$ consecutive zeros is
$$ N(m,k)_q = \sum_{j=0}^{\lfloor \frac{m}{k} \rfloor} \binom{m-kj}{j}(1-q)^j q^{m-(k+1)j} - \sum_{j=0}^{\lfloor \frac{m-k}{k} \rfloor} \binom{m-k-kj}{j}(1-q)^j q^{m-k-(k+1)j}, $$
where $1 \le k \le m$ is the constraint.
It would be nice, if some can confirm this formula. Is there a possibility to remove the constraint? So I would like to vary $m$ and $k$, even that the formula is valid for $ m \le k $. Or is it already general and the second sum is a "empty" sum if the upper limit is negative?