For example: [1,2,3,4] and k=3 parts should yield
[1],[2],[3,4]
[1],[3],[2,4]
[1],[4],[2,3]
[2],[3],[1,4]
[2],[4],[1,3]
[3],[4],[1,2]
as an output.
For k=2 with the same set we would get
[1],[2,3,4]
[2],[1,3,4]
[3],[1,2,4]
[4],[1,2,3]
[1,2],[3,4]
[1,3],[2,4]
[1,4],[2,3]
instead.
Can anyone give me some advice here? Thanks a lot.
Stirling numbers of second kind: $S(n,k)$ is the number of partitions of an $n$-element set into $k$ nonempty pairwise disjoint subsets. There is a recursion for computing these numbers: $S(n,1)=1=S(n,n)$ and $S(n,k+1) = k\cdot S(n,k) + S(n,k-1)$.