<s>[INST] Summation closed form. I have tried to figure out how to get the close form of:
$$\sum_{k=0}^n k^22^{n-k}.$$
I tried to write down each number of the summation but couldn't find any thing to do with that.. 
can please someone explain to me how to do it? thanks a lot! :)
 [/INST] We can solve it by convolution of generating functions:
\begin{align*}
  A(x) &= \sum_{k\ge 0} k^2\, x^k = \frac{x+x^2}{(1-x)^3} \\
  B(x) &= \sum_{k\ge 0} 2^k\, x^k = \frac{1}{1-2\, x} \\
  A(x)\cdot B(x) &= \sum_{n\ge 0} \left(\sum_{k= 0}^n k^2\, 2^{n-k} \right) x^n = \frac{x+x^2}{(1-x)^3(1-2\, x)}
\end{align*}
Then we can extract $[x^n]$ by doing partial fractions:
\begin{align*}
  A(x)\cdot B(x) &= \frac{6}{1-2 \, x } - \frac{2}{{\left(1-x\right)}^{3}} - \frac{1}{{\left( 1-x\right)}^{2}} -\frac{3}{1-x} 
\end{align*}
Hence,
\begin{align*}
  \sum_{k= 0}^n k^2\, 2^{n-k} &= 6\cdot 2^n - 2\, \binom{n+2}{2} - \binom{n+1}{1} - 3 \\
  &= 6\cdot 2^n - n^2 - 4\, n - 6
\end{align*}
</s>