Example 7 $n$ cells are arranged in a row, to be painted with red, white, and black colors, with each cell painted one color, and it is required that the number of cells painted red must be even. How many different ways are there to paint the cells?


Let $G_{1}(t) 、 G_{2}(t) 、 G_{3}(t)$ be the generating functions for enumerating red, white, and black respectively, then
$$
\begin{array}{l}
G_{1}(t)=1+\frac{t^{2}}{2!}+\frac{t^{4}}{4!}+\cdots=\frac{1}{2}\left(e^{t}+e^{-t}\right) \\
G_{2}(t)=G_{3}(t)=1+t+\frac{t^{2}}{2!}+\frac{t^{3}}{3!}+\cdots=e^{t}
\end{array}
$$

Therefore, $G_{t}(t)=G_{1}(t) \cdot G_{2}(t) \cdot G_{3}(t)=\frac{1}{2}\left(e^{t}+e^{-t}\right) \cdot e^{t} \cdot e^{t}=\frac{1}{2}\left(e^{3 t}+e^{t}\right)$
$$
=\frac{1}{2}\left[\sum_{n=0}^{\infty} 3^{n} \cdot \frac{t^{n}}{n!}+\sum_{n=0}^{\infty} \frac{t^{n}}{n!}\right]=\sum_{n=0}^{\infty} \frac{1}{2}\left(3^{n}+1\right) \cdot \frac{t^{n}}{n!}
$$

If we denote $b_{n}$ as the number of different coloring methods, then $b_{n}=\frac{1}{2}\left(3^{n}+1\right), n=1,2, \cdots$ The last example is from the 3rd China Girls Mathematical Olympiad.