Let S= { f | f: A $\rightarrow$ B, |Image(f)|=k}.
|A|=m, |B|=n. where k $ \le n, k \le m $
|S|=$ {n \choose k} $ S(m,k) k!.
where S(m,k) are the striling numbers of the second kind. What I can't understand is how does k! fit in ? Why do we have to multiply by k! ?
Also we know that the total number of functions from A $\rightarrow $ B is $n^{m}$.
So is |S|=$n^{m}$ ?
There are $\binom{n}k$ ways to pick a subset $I$ of $B$ of cardinality $k$ to be the image of a function $f\in S$. There are ${m\brace k}$, or in your notation $S(m,k)$, ways to partition $A$ into $k$ non-empty subsets. And there are then $k!$ ways to pair up these subsets with the $k$ members of $I$. That is, if the $k$ non-empty subsets of $S$ are $P_1,\ldots,P_k$, we can assign them in this order to any permutation of the $k$ members of $I$, and there are $k!$ such permutations. Thus, there are altogether
$$\binom{n}k{m\brace k}k!$$
such funtions. This is not $n^m$, as you can verify by calculating an example or two with small numbers; $n^m$ is the total number of functions from $A$ to $B$, so it includes those whose images have each possible size from $1$ through $n$. This means that
$$n^m=\sum_{k=1}^n\binom{n}k{m\brace k}k!\;.$$