Derivation (counting surjections)

Let $$\begin{align*} \Omega &= \set{\text{functions }\set{1,\ldots, m}\to\set{1,\ldots,n}}, \\ A &= \text{subset of surjections}, \\ A_i &= \sb{\omega\in\Omega}{i\not\in\im\omega},\quad i=1,2,\ldots,n. \end{align*}$$ Then $$ A = (A_1\cup A_2\cup\ldots\cup A_n)^\complement. $$

For sequence indices $i_1<i_2<\ldots<i_k$, $$ |A_{i_1}\cap A_{i_2}\cap\ldots \cap A_{i_k}| = |\set{\text{functions } \set{1,\ldots,m}\to\set{1,\ldots,n}\setminus\set{i_1,\ldots, i_k}}| = (n-k)^m. $$

So by inclusion-exclusion, $$\begin{align*} |A_1\union A_2\union \ldots\union A_n| &= \sum_{k=1}^n (-1)^{k+1} \sum_{1\leq i_1<\ldots<i_k\leq n} |A_{i_1}\cap A_{i_2}\cap\ldots\cap A_{i_k}| \\ &= \fsum k1n (-1)^{k+1} \pmat{n\\k} (n-k)^m \\ \end{align*}$$ and therefore $$ |A| = |\Omega| - |A_1\cup\ldots\cup A_n| = \fsum k0n (-1)^k\pmat{n\\k}(n-k)^m.$$