Counting number of occurences Let $1\leq k\leq n$. We find all finite sequences of positive integers with sum $n$. Suppose that the term $k$ occurs a total of $T(n, k)$ times in all these sequences. 

Find $T(n, k)$.

As an example to make things more clear: $T(3,1)=5$, $T(3,2)=2$ and $T(3,3)=1$
This on base of the sums $1+1+1=3$, $1+2=3$, $2+1=3$ and $3=3$.
In this I'm pretty sure we can do this by choosing $r$ $x$'s and letting them be equal to $k$ individually, in groups of $2$ and so on. We can then sum it over $r$. But I'm unable to write a solution and obtain an expression for $T(n,k)$. 
Thanks in advance!

With $q$ the length of the sequence and $k$ marked with $u$ we get the
generating function
$$G(z, u) = \sum_{q\ge 0} (z+z^2+\cdots+uz^k+\cdots)^q
\\ = \sum_{q\ge 0} z^q (1+z+\cdots+uz^{k-1}+\cdots)^q
\\ = \sum_{q\ge 0} z^q \left(\frac{1}{1-z} + (u-1)z^{k-1}\right)^q
\\ = \frac{1}{1-z(1/(1-z)+(u-1)z^{k-1})}
\\ = \frac{1-z}{1-z-z(1+(u-1)(1-z)z^{k-1})}.$$
The desired quantity is given by
$$[z^n] \left.
\frac{\partial}{\partial u} G(z, u)\right|_{u=1}
\\ = [z^n] \left. \frac{1-z}{(1-z-z(1+(u-1)(1-z)z^{k-1}))^2}
(z (1-z) z^{k-1})\right|_{u=1}
\\ = [z^n] \frac{1-z}{(1-2z)^2} (z (1-z) z^{k-1})
\\ = [z^n] \frac{1-2z+z^2}{(1-2z)^2} z^k
= [z^{n-k}] \frac{1-2z+z^2}{(1-2z)^2}.$$
We thus have for $k=n$ the value one, corresponding to the composition
$n=n$, for $k=n-1$ the value
$$[z^1] \frac{1-2z+z^2}{(1-2z)^2} = 4 - 2 = 2$$
corresponding to  the compositions  $1 +  (n-1) = (n-1)  + 1$  and for
$k\le n-2$
$$(n-k+1) \times 2^{n-k} - (n-k) \times 2^{n-k}
+ (n-k-1) \times 2^{n-k-2}
\\ = 2^{n-k} + (n-k-1) \times 2^{n-k-2}.$$
for a closed form of
$$\bbox[5px,border:2px solid #00A000]{
2^{n-k-2} (n-k+3).}$$
We clearly obtain zero when $k\gt n.$
