Find number of solutions $ x_1+x_2+x_3+x_4+x_5+x_6+x_7 = 7 $ where $x_i \in \left\{ 0,1,2 \right\}$

Hint: The answer is the coefficient of $x^7$ in $(1 + x + x^2)^7$.


Hint: You want the coefficient of $x^7$ in $$ (1+x+x^2)^7=\left(\frac{1-x^3}{1-x}\right)^7=(1-x^3)^7\times (1-x)^{-7} $$ Now, $(1-x^3)^7$ and $ (1-x)^{-1}$ are the generating functions of two nice series, $a_n$ and $b_n$; can you find them? Once you do, since you want the convolution of these two series: $$ \sum_{k=0}^7 a_kb_{n-k}. $$ Furthermore, you will find that $a_k$ equals zero unless $k$ is a multiple of $3$, so that the above summation is has only three nonzero terms and is therefore easily computable by hand.


The number of unique combinations of numbers summed to achieve $7$ in such a way are $$\{1,1,1,1,1,1,1\}$$ $$\{2,1,1,1,1,1\}$$ $$\{2,2,1,1,1\}$$ $$\{2,2,2,1\}$$ So the total number of solutions is given by $$\frac{7!}{7!}+\frac{7!}{5!}+\frac{7!}{3!\cdot2!\cdot2!}+\frac{7!}{3!\cdot3!}=393$$