Coefficient of terms in expansions Can we have general method to find coefficient
of $x^ k$ in exapansion of $(1+x+x^2)^n$?
like if it is k=3,4 or something like that we can use 
multinomial expansions and solve but when lets say 
k is n , using multinomial to solve gives sets of equations
whose answer set is large.
 A: In general: $$\left(a+b+c\right)^{n}=\sum_{r+s+t=n}\binom{n}{r,s,t}a^{r}b^{s}c^{t}$$
where $r,s,t$ are nonnegative integers, and leading to:
$$\left(1+x+x^{2}\right)^{n}=\sum_{r+s+t=n}\binom{n}{r,s,t}x^{s+2t}$$
This tells us that
$$\sum_{r+s+t=n\wedge s+2t=k}\binom{n}{r,s,t}\text{ is the coefficient
of }x^{k}$$
Also you could say that: $$\sum_{r\in S}\frac{n!}{r!\left(2n-2r-k\right)\left(k-n+r\right)!}\text{ is the coefficient
of }x^{k}$$
where $r\in S\iff r\geq0\wedge2n-2r-k\geq0\wedge k-n+r\geq0$.
If I am not mistaken (check me) then this comes to:
$$\sum_{r=n-k}^{n-\lceil\frac{1}{2}k\rceil}\frac{n!}{r!\left(2n-2r-k\right)!\left(k-n+r\right)!}\text{ is the coefficient of }x^{k}$$
A: We can apply the binomial theorem twice in order to derive the trinomial coefficients. It is convenient to use the coefficient of operator $[x^k]$ to denote the coefficient of $x^k$ in a series.

We obtain for $0\leq k\leq n$:
  \begin{align*}
\color{blue}{[x^k]}&\color{blue}{(1+x+x^2)^n}\\
&=[x^k]\sum_{j=0}^n\binom{n}{j}(x+x^2)^j\\
&=[x^k]\sum_{j=0}^n\binom{n}{j}x^j(1+x)^j\\
&=[x^k]\sum_{j=0}^n\binom{n}{j}x^j\sum_{l=0}^j\binom{j}{l}x^l\\
&=\sum_{j=0}^{k}\binom{n}{j}[x^{k-j}]\sum_{l=0}^j\binom{j}{l}x^l\tag{1}\\
&\,\,\color{blue}{=\sum_{j=0}^{k}\binom{n}{j}\binom{j}{k-j}}\tag{2}
\end{align*}

Comment:


*

*In (1) we use the linearity of the coefficient of operator and apply the rule $[x^{p-q}]A(x)=[x^p]x^qA(x)$.

*In (2) we select the coefficient of $x^{k-j}$.
