4. Let $x_{1}, x_{2}, x_{3} \in \mathbf{Z}, 0 \leqslant x_{1} \leqslant 2, 1 \leqslant x_{2} \leqslant$ $3, 1 \leqslant x_{3} \leqslant 4$. Then the number of solutions to $x_{1}+x_{2}+x_{3}=7$ is ( ).
(A) 6
(B) 7
(C) 8
(D) 9
4. A.

Consider the coefficient of $x^{7}$ in the generating function $\left(1+x+x^{2}\right)\left(x+x^{2}+\right.$ $\left.x^{3}\right)\left(x+x^{2}+x^{3}+x^{4}\right)$
$$
\Leftrightarrow x^{2}\left(1+x+x^{2}\right)^{2}\left(1+x+x^{2}+x^{3}\right) \text { of } x^{7}
$$

coefficient
$\Leftrightarrow\left(1+x+x^{2}\right)^{2}\left(1+x+x^{2}+x^{3}\right)$ of $x^{5}$ coefficient
$$
\Leftrightarrow\left(1+2 x+3 x^{2}+2 x^{3}+x^{4}\right)\left(1+x+x^{2}+x^{3}\right)
$$

coefficient of $x^{5}$
$$
=3 \times 1+2 \times 1+1 \times 1=6 \text {. }
$$