Number of surjections with injective restrictions Given a partitition of an $n$-element set $N$ into subsets of size $(n_i)_{i=1\ldots,k}$ and an $m$-element set $M$. How many surjections $N\rightarrow M$ are there such that the restriction to each of the smaller subsets is injective?
For example, if $k=1$ and $n_1 = N$, then I am asking for the number of bijections $N\rightarrow M$. On the other hand, if $k=n$ and $n_i=1$ for every $i$, then I am asking for the number of surjections from $N$ to $M$.
My motivation for this question comes from http://code.google.com/codejam/contest/3014486/dashboard#s=p3. The contest is already over so I this it is OK to ask here.
 A: Let us characterize one of the accepted functions according to the fibers of the image. the fiber of each element of the co-domain must first of all be non-empty. And second of all if we look at the part of the fibre belonging to a subset it can either contain no elements or exactly one. Finally notice all of the fibers of any two elements are disjoint disjoint.
Therefore the number of function is equal to the number of ways to distribute the $n$ elements in the domain among the $m$ elements of the codomain so each of them gets at least one element and none of them have more than $1$ from the same subset.We will count in how many ways we can do this if the elements within each subset where identical. 
If they where identical then the answer would be the coefficient of $x_1^{n_1}\dots x_k^{n_k}$ in $[(1+x_1)(1+x_2)\dots(1+x_n)-1]^m$ where $(1+x_1)\dots(1+x_n)−1$ corresponds to the chips placed on each square; zero or one of each color, but at least one chip.
That coefficient is $$\sum_{l=0}^m (-1)^{m-l}\binom ml \binom l{n_1}\cdots \binom l{n_k}.$$
This formula can be proved directly by inclusion-exclusion: $\binom ml \binom l{n_1}\cdots \binom l{n_k}$ is the number of ways to choose $k$ of the $m$ squares and place all of the chips on these squares, with at most one chip of each color on each square (but with some squares possibly having no chips).
So the final result is $$n_1!n_2!\cdots n_k!\sum_{l=0}^m (-1)^{m-l}\binom ml \binom l{n_1}\cdots \binom l{n_k}.$$
