# Calculating combinations when some objects are guaranteed to be selected, and others are not

I've been working on problems involving sorting objects into three groups of four items each for a programming project. I'm fairly confident that the number of distinct ways to sort 12 objects into three groups of four unordered objects can be calculated in the form:

$$C(12,4)*C(8,4)*C(4,4)$$

Given that the order of my groups doesn't matter, I can divide this product by $3!$, giving 5775 combinations.

If I were instead selecting from 18 objects, I presume that the answer would be calculated very similarly, as follows:

$$C(18,4)*C(14,4)*C(10,4)$$

Divided again by $3!$, I come up with 107,207,100.

Now my issue is that I may have a set of >12 objects, for which I again select 12 of those objects into three groups of four, but some of the objects in the set are guaranteed to be selected into these groups, while others are not.

For example, I could have 18 objects, for which 10 of these objects are guaranteed to be selected, while the other 2 will be selected at random from the remaining 8.

I think the total number of combinations can be calculated by multiplying the number of combinations of sorting 12 objects into three groups of four by $C(8,2)$, thus: 5775 x 28 = 161,700.

But what I'm having particular trouble with is the following: how many possible combinations of a single group are there? That is, for my example case: how many ways are there to pick 4 unordered objects from a set of 18 possible objects, but there can be no more than 2 objects from a subset of 8? And then, once the first group is selected, how do I calculate the remaining combinations? Presumably, the number of combinations for the second and third groups differs depending on how many items from the subset have already been selected.

[...] how many ways are there to pick 4 unordered objects from a set of 18 possible objects, but there can be no more than 2 objects from a subset of 8?

Since those 10 are guaranteed to be selected, first decide which 2 are selected from those 8. Then consider:

None from the 2 + one from the 2 + two from the 2

$${8\choose2}\cdot\left({2\choose0}{10\choose4}+{2\choose1}{10\choose3}+{2\choose2}{10\choose2}\right).$$

[...] And then, once the first group is selected, how do I calculate the remaining combinations?

first group has $0$ from the two

(2,0), (1,1)

$${2\choose2}{6\choose2}\cdot{4\choose4},\\ {2\choose1}{6\choose3}\cdot{1\choose1}{3\choose3};$$

first group has $1$ from the two

(1,0)

$${1\choose1}{7\choose3}\cdot{4\choose4};$$

first group two from the two

(0, 0)

$${8\choose4}\cdot{4\choose4}.$$