Number of ways to count mapping of n elements to k elements where each element is 'used' at least j times I have a 'box' of n things. Each one of these n things must be assigned to one of k many things where $n \gt k$. Finally, there is the constraint that every one of these k many things must have associated with it at least j many n.
I.E There are 12 goats in a field. Each goat must be assigned to one of 4 pens. Each pen must have at least 2 goats. How many total ways are there of assigning the goats?
Here is my intuition and here is why I'm getting stuck: I want to use the Stirling numbers to solve this problem. Firstly, I thought I could use the fact that $n^m = \sum_{k = 0}^{m} k!S(m, k)\binom{n}{k}$ (The number of functions by the bijection principle in terms of the Stirling numbers) and then exploit something to do with the fact that every image is overcounted by at least 2. I'm just finding it really difficult to know exactly what to do.
 A: You can do this by inclusion-exclusion, though it is not particularly pretty. Let $U$ be the set of all $k^n$ attributions of each of the $n$ goat to one of the $k$ pens. For $i=1,2,\ldots,k$ let $A_i$ be the set of attributions that assign strictly less than $j$ goats to pen $i$ (which is undesirable) so that you are looking for the size of $U\setminus\bigcup_{i=1}^kA_i$. The principle of inclusion-exclusion says that this size equals
$$
  \sum_{P\subseteq\{1,2,\ldots,k\}}(-1)^{\#P}\#\bigcap_{i\in P}A_i,
$$
where the term for $P=\emptyset$ is taken to be $\#U$ (in other words the intersection of none of the subsets $A_i$ is taken to be the universe$~U$). So for a given subset $P$ of indices, we need to know the size of the corresponding intersection $\bigcap_{i\in P}A_i$. Elements of the intersection can be specified by giving $l=\#P$ numbers $n_i\in\{0,1,\ldots,j-1\}$ (one for each $i\in P$) that count the number of goats in those pens $i$, giving the subset of those $n_i$ goats for every $i\in P$, and assigning the remaining $r=n-\sum_{i\in P}n_i$ goats to the remaining $k-l$ pens. The size of the intersection is then the sum over all such tuples $(n_i)_{i\in P}$ of $\binom n{n_{i_1},n_{i_2},\ldots,n_{i_l},r}(k-l)^r$ (the first factor is a multi-nomial coefficient). That is a big summation, but its value only depends on $l$; call its value $\Sigma_l$ (with in particular $\Sigma_0=\#U=k^n$). Then the final answer is
$$
\#(U\setminus\bigcup_{i=1}^kA_i)=\sum_{l=0}^k(-1)^l\binom kl\Sigma_l.
$$
