I have a problem concerning enumerating partitions of a set of identical objects. I know, now someone is going to talk about Stirling number of second kind, but I'm quite sure this is not the answer.
I will describe the problem with an example. Suppose to have a set of $n$ identical objects. The problem is to enumerate and to generate all the partitions obtained with $k$ subsets, like in the following example.
Let $n=5$, $k=3$. Define $B_i$, with $i=1,\dots,k$ the set of the partition. Hence, I can partition the set of $n$ objects by constructing the following partitions:
- $|B_1|=3$, $|B_2|=1$, $|B_3|=1$.
- $|B_1|=2$, $|B_2|=2$, $|B_3|=1$.
Notice that: $(i)$ must result $B_i\neq \emptyset$; $(ii)$ partitions like, for instance, $|B_1|=1$, $|B_2|=3$, $|B_3|=1$ or $|B_1|=1$, $|B_2|=1$, $|B_3|=3$ must not be considered, since are in practice already considered in the first partition (i.e. $|B_1|=3$, $|B_2|=1$, $|B_3|=1$).
Since objects are all identical, I only express the sets cardinality and I doesn't care about the specific object allocated to a set of the partition.
The problem is particular useful in the formulation of algorithms for assignment problems.
You want the function $P(n,k)$ described after formula $(58)$ of this MathWorld article, giving the number of partitions of $n$ into exactly $k$ parts. This is always the same as the number of partitions of $n$ with largest part $k$. For this function, unlike the intermediate function in the Wikipedia article, $P(5,3)=2$; you’ve exhibited the two partitions of $5$ into $3$ parts, and the two partitions of $5$ with maximum part $3$ are $3+2$ and $3+1+1$. The link has a nice recurrence for $P(n,k)$, formula $(59)$:
$$P(n,k)=P(n-1,k-1)+P(n-k,k)\;,$$
with initial conditions
$$\begin{align*} &P(n,k)=0\quad\text{if}\quad k>n\\ &P(n,n)=1\quad\text{for}\quad n\ge 0\\ &P(n,0)=0\quad\text{for}\quad n\ge 0\;. \end{align*}$$
The recurrence is easily verified. Every partition of $n$ into $k$ parts, at least one of which is $1$, is obtained by adding a $1$ part to a partition of $n-1$ into $k-1$ parts. Every partition of $n$ into $k$ parts, all of which are at least $2$, is obtained from a partition of $n-k$ into $k$ parts by adding $1$ to each part.