Example 4.29 Place $n(n \geqslant 1)$ distinct balls into 4 distinct boxes $A_{1}$, $A_{2}$, $A_{3}$, $A_{4}$, find the number of different ways to place the balls, $g_{n}$, such that $A_{1}$ contains an odd number of balls, and $A_{2}$ contains an even number of balls.
Let $n$ balls be denoted as $a_{1}, a_{2}, \cdots, a_{n}$, then any method of placing the balls that satisfies the problem corresponds to an $n$-repeated permutation of the 4-element set $A=\left\{A_{1}, A_{2}, A_{3}, A_{4}\right\}$. The correspondence is as follows: if ball $a_{i}$ is placed in box $A_{k}$, then $A_{k}$ is placed in the $i$-th position. Thus, $g_{n}$ equals the number of $n$-repeated permutations of the 4-element set $A=\left\{A_{1}, A_{2}, A_{3}, A_{4}\right\}$ that satisfy the condition: “$A_{1}$ appears an odd number of times, $A_{2}$ appears an even number of times,” and thus $g_{n}$ is
$$
\begin{aligned}
E(t)= & \left(t+t^{3} / 3!+t^{5} / 5!+\cdots\right) \cdot\left(1+t^{2} / 2!+t^{4} / 4!+\cdots\right) \cdot \\
& \left(1+t+t^{2} / 2!+t^{3} / 3!+\cdots\right)^{2}
\end{aligned}
$$

The coefficient of $t^{n} / n!$ in the expansion, and
$$
\begin{aligned}
E(t) & =\frac{\mathrm{e}^{t}-\mathrm{e}^{-t}}{2} \cdot \frac{\mathrm{e}^{t}+\mathrm{e}^{-t}}{2} \cdot \mathrm{e}^{2 t} \\
& =\frac{1}{4}\left(\mathrm{e}^{4 t}-1\right)=\sum_{n=1}^{\infty} \frac{4^{n}}{4} t^{n} / n! \\
& =\sum_{n=1}^{\infty} 4^{n-1} t^{n} / n!,
\end{aligned}
$$

Therefore,
$$
g_{n}=4^{n-1} .
$$