How many possibilities? Suppose we have a vector $x=(x_0,x_1,x_2,\ldots,x_{n-1})$ with $x_i\in\{0,1,2\}$ for all $i=0,1,...,n-1$.
Define
$$
x'=\sum_{i=0}^{n-1}x_i,
$$
then
$$
0\leq x'\leq n\cdot 2..
$$
I would like to know how many possibilities of vectors there are, for fixed $0\leq m\leq n\cdot 2$, to have
$$
x'=m.
$$
I think, for example, for $x'=0$ and $x'=n\cdot 2$, we only have one possibility, namely $(0,...,0)$ and $(2,...,2)$. But maybe there is some general formula.
I don’t know whether there is some Trick.
 A: The expression providing the result you need is
$$
I_n(m)=\sum_{x_0=0}^2\cdots \sum_{x_{n-1}=0}^2 \delta_{\sum_i x_i,m}\ ,
$$
where $\delta_{a,b}=1$ if $a=b$ and $=0$ otherwise. Basically this is a counting device: you get a '$+1$' for every configuration $\mathbf{x}$ such that the sum of the components is equal to $m$.
Using the integral representation
$$
\delta_{a,b}=\int_0^{2\pi}\frac{d\xi}{2\pi}e^{\mathrm{i}\xi (a-b)}
$$
you get
$$
I_n(m)=\int_0^{2\pi}\frac{d\xi}{2\pi}e^{\mathrm{i}\xi m}\left(\sum_{x=0}^2 e^{-\mathrm{i}\xi x}\right)^n=\int_0^{2\pi}\frac{d\xi}{2\pi}e^{\mathrm{i}\xi m}(1+e^{-\mathrm{i}\xi}+e^{-2\mathrm{i}\xi})^n\ .
$$
Expanding with the multinomial theorem, you can get a more explicit expression. Mathematica can handle this integral for specific values of $m$ and $n$. For example, for $m=38$ and $n=29$ you get $I_n(m)=774369291150$.
A: I don't know why John Don didn't post this as an answer. This is a combinatorial problem, covered by generating functions (for example this one or this one and a really good reading here).
So, we want 
$$\sum\limits_{i=0}^{n-1} x_i =m$$
$$0\leq x_i\leq 2, \forall x_i=0..n-1$$
The generating function is 
$$(1+x+x^2)(1+x+x^2)...(1+x+x^2)=(1+x+x^2)^n$$
and the coefficient near $x^{m}$ term is the answer. Considering multinomial theorem:
$$(1+x+x^2)^n=\sum\limits_{k_1+k_2+k_3=n}\binom{n}{k_1,k_2,k_3}1^{k_1}\cdot x^{k_2}\cdot x^{2k_3}=\\
\sum\limits_{k_1+k_2+k_3=n}\frac{n!}{k_1!k_2!k_3!} x^{k_2+2k_3}$$
In other words, the answer is
$$\sum\limits_{k_1+k_2+k_3=n\\k_2+2k_3=m}\frac{n!}{k_1!k_2!k_3!}$$
