TITLE: Number of sequences of length $m$ such that $1$ is never followed immediately by $0$
QUESTION [8 upvotes]: Find the number of sequences of length $m$ consisting of only digits, where each digit is in $\{0,1,2\}$ and such that $1$ is never followed immediately by $0$.

Attempt: I tried taking 10 as a block, but I got nowhere. I found the Mathematics question Number of permutations of thet set $\{1,2,...,n\}$ in which $k$ is never followed immediately by $k+1$.
Using that, since I need to remove only 1 followed by 0, I get only one set $A_1$ so, $3^m$ - 6 (3*2). Pick the other number in three ways, and we can permute 10 and other number in two ways). Is this right?
I am from a non-math background; kindly consider this if possible.

REPLY [2 votes]: This answer is based upon the Goulden-Jackson Cluster Method.

We consider the set words of length $m\geq 0$ built from an alphabet $$\mathcal{V}=\{0,1,2\}$$ and the set $B=\{10\}$ of bad words, which are not allowed to be part of the words we are looking for. We derive a generating function $f(s)$ with the coefficient of $s^m$ being  the number of searched words of length $m$.

According to the paper (p.7) the generating function $f(s)$  is
\begin{align*}
f(s)=\frac{1}{1-ds-\text{weight}(\mathcal{C})}\tag{1}
\end{align*}
with $d=|\mathcal{V}|=3$, the size of the alphabet and $\mathcal{C}$ the weight-numerator of bad words with
\begin{align*}
\text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[10])
\end{align*}
We calculate according to the paper
\begin{align*}
\text{weight}(\mathcal{C}[10])&=-s^2\\
\end{align*}
and get

\begin{align*}
f(s)&=\frac{1}{1-ds-\text{weight}(\mathcal{C})}\\
&=\frac{1}{1-3s+s^2}\\
\end{align*}
Partial fraction decomposition and expansion of $f(s)$ results in
\begin{align*}
f(s)&=\frac{3+\sqrt{5}}{2\sqrt{5}}\cdot\frac{1}{1-\frac{3+\sqrt{5}}{2\sqrt{5}}s}
-\frac{3-\sqrt{5}}{2\sqrt{5}}\cdot\frac{1}{1-\frac{3-\sqrt{5}}{2\sqrt{5}}s}\\
&\\
&=\frac{1}{\sqrt{5}}\sum_{m=0}^{\infty}\left[\left(\frac{3+\sqrt{5}}{2}\right)^{m+1}-\left(\frac{3-\sqrt{5}}{2}\right)^{m+1}\right]s^m\\
\\
&=1+3s+8s^2+21s^3+\color{blue}{55}s^4+144s^5+377s^6+\cdots
\end{align*}
  with the coefficient of $s^m$ giving the number of valid words of length $m$.

The number  of valid words of  length $4$ is $55$. Here is a list showing all $4^3=81$ words and the $26$ invalid words marked with blue.
\begin{array}{ccccccccc}
0000&0\color{blue}{10}0&0200&\color{blue}{10}00&1\color{blue}{10}0&1200&2000&2\color{blue}{10}0&2200\\
0001&0\color{blue}{10}1&0201&\color{blue}{10}01&1\color{blue}{10}1&1201&2001&2\color{blue}{10}1&2201\\
0002&0\color{blue}{10}2&0202&\color{blue}{10}02&1\color{blue}{10}2&1202&2002&2\color{blue}{10}2&2202\\
00\color{blue}{10}&01\color{blue}{10}&02\color{blue}{10}&\color{blue}{10}\color{blue}{10}&11\color{blue}{10}&12\color{blue}{10}&20\color{blue}{10}&21\color{blue}{10}&22\color{blue}{10}\\
0011&0111&0211&\color{blue}{10}11&1111&1211&2011&2111&2211\\
0012&0112&0212&\color{blue}{10}12&1112&1212&2012&2112&2212\\
0020&0120&0220&\color{blue}{10}20&1120&1220&2020&2120&2220\\
0021&0121&0221&\color{blue}{10}21&1121&1221&2021&2121&2221\\
0022&0122&0222&\color{blue}{10}22&1122&1222&2022&2122&2222\\
\end{array}