There are 10 slots and some marbles: 5 red, 3 blue, 2 green, how many ways can you fit those marbles into those slots?
Those marbles fit in 10!/(5! 3! 2!) ways
Now we have 10 slots but the slots have a restriction: slots #1 thru #4 can fit red, blue, or green marbles. But the remaining can only red or blue.
Easy enough, place the two green in the first 4 slots
4!/(2! 2!) ways and then place red and blue in the
remaining 8 slots 8!/(5! 3!) ways
THE QUESTION: How many ways can we place these marbles in the following slots (or arbitrary marbles into slots with arbitrary restrictions):
- Slots #1 thru #4: can take red, green, blue
- Slots #5 thru #7: can take red, green
- Slots #8 thru #10: can take red, blue
I have one "solution". The answer is:
count(5 red, 3 blue, 2 green, slots #1 thru #10)
= count(4 red, 3 blue, 2 green, slots #2 thru #10)
+ count(5 red, 2 blue, 2 green, slots #2 thru #10)
+ count(5 red, 3 blue, 1 green, slots #2 thru #10)
My recursive solution does produce the answer for this question. But is there a general way to solve this problem directly?
As the conditions become more complicated, the counting becomes more complicated. Your approach is very general.It doesn't satisfy one of my slogans-forget what you don't need to know. As you follow the recursive chain, the distributions that start red green will not be combined with the ones that start green red. Following that slogan, I would start with the weak compositions of 5 red marbles into three parts, with a calculation of the number of combinations in each group. So the composition $2,1,2$ indicates there are two reds in $1-4$, one in $5-7$ and two in $8-10$. It gets counted ${4\choose 2}{3 \choose 1}{3 \choose 2}$ times. Then since all the greens are used up, we are done with this composition. Which approach is easier will depend sensitively on the problem.