1. Find the number of sequences that satisfy the following conditions: the number of terms is $n$, each term is 0 or 1 or 2, and 0 cannot be the preceding term or the following term of 2.
Let the number of sequences that satisfy the condition be $f_{n}$. Let the number of sequences ending with 0 be $a_{n}$, the number of sequences ending with 1 be $b_{n}$, and the number of sequences ending with 2 be $c_{n}$. Then
$$
f_{n}=a_{n}+b_{n}+c_{n} .
$$

It is easy to see that $a_{n}=a_{n-1}+b_{n-1}$,
$$
\begin{array}{l}
b_{n}=a_{n-1}+b_{n-1}+c_{n-1}, \\
c_{n}=b_{n-1}+c_{n-1} .
\end{array}
$$

Then $f_{n}-2 f_{n-1}-f_{n-2}=0$, and $f_{1}=3, f_{2}=7$.
$$
\text { Hence } f_{n}=\frac{1}{2}\left[(1+\sqrt{2})^{n+1}+(1-\sqrt{2})^{n+1}\right] \text {. }
$$