<s>[INST] Is there a formula for computing the number of arrangements from a set of N elements groupped in K groups? Eg: N=3, K=2
There will be two groups in each solution. We need to calculate the number of such possible solutions. Consider the set S={1,2,3}. The possible solutions are:
{1} {2,3}
{1} {3,2}
{2} {1,3}
{2} {3,1}
{3} {1,2}
{3} {2,1}
{1,2} {3}
{2,1} {3}
{1,3} {2}
{3,1} {2}
{2,3} {1}
{3,2} {1}

The result for this example is: 12.
Eg: N=4, K=3
{1} {2} {3,4}
{1} {2} {4,3}
{1} {2,3} {4}
{1} {3,2} {4}
....

Can we generalize this formula?
 [/INST] Consider an arrangement of a set $S = \{ a_1, a_2, a_3, \dots, a_n\}$.
We need to partition this set into $K$ groups such that each group contains more than one element such that the relative order of elements remain same. For example for $S = \{1,2,3\}$, the partition $\{1\},\{2,3\}$ will be valid but $\{2\},\{1,3\}$ will be invalid.
Let $x_i$ be the number of elements in $i^{th}$ partition, so we have $$x_1 + x_2 + x_3 + \dots + x_k = n$$
where each $x_i \ge 1$. This is a classical problem and we know the number of ways for the above problem is $$P = \binom{n-1}{k-1}$$
There are $n!$ sets, S are possible so number of arrangements will be equal to $n!*P$.
</s>