# Counting ways to distribute 7 apples and 5 pears between 4 children with restriction

I was given the following problem:

In how many ways $$7$$ apples and $$5$$ pears can be distributed between four kids if each child gets three fruits?

My counting is not the strongest, here is how I approached the problem: first I will distribute the pears then fill the missing spots with apples. We can use stars and bars to count the distribution of pears: $$\binom{5+4-1}{4-1}=\binom 8 3=56$$. We need to subtract cases when there are more than $$3$$ pears: $$4$$ (one basket with $$5$$ pears) and $$\frac{4!}{2!}$$ ($$4$$ pears in one basket and one in some other basket). Thus, the total number is $$56-4-12=40$$. Is this correct? Is there a better way to explain this problem to students?

• It looks precisely correct to me. Commented Dec 21, 2021 at 2:40
• The one way I can see that you can simplify the explanation a bit is to combine the two cases you need to subtract: For kid $k$, the combination is disallowed if that kid has $4$ pears and the fifth pear goes to any of the $4$ kids, so you subtract $4 \cdot 4=16$ disallowed combinations from the $56$ combinations possible with no restrictions. Commented Dec 21, 2021 at 3:17

I'll do the apples rather than the pears to illustrate the simplification I have in mind. There are $$\binom {10}{3}=120$$ ways to distribute $$7$$ apples among $$4$$ kids without restriction. If no kid can have $$4$$ or more apples, then after assigning $$4$$ of the apples to one of the kids, there are $$\binom 63=20$$ ways to distribute the remaining $$3$$ apples among the $$4$$ kids, so there are $$4 \cdot 20=80$$ disallowed combinations, meaning $$40$$ allowed combinations.

• Thank you for the answer and your comment, it helped me to understand the solution better. Commented Dec 21, 2021 at 13:15

One way is by considering partitions. It is sufficient to just distribute $$5$$ pears among the kids; the apples are complementary.

Then consider the partitions of $$5$$ into atmost four parts such that no part is larger than $$3$$. These can be listed easily

• $$(3,2,0,0)$$
• $$(3,1,1,0)$$
• $$(2,2,1,0)$$
• $$(1,1,1,2)$$

First item means one kid gets $$3$$ pears, second gets $$2$$ and other two get none. Others are similar.

Since the kids are distinct, total contribution is (in order) $$\binom{4}{1}\binom{3}{1}+ \binom{4}{1}\binom{3}{2} + \binom{4}{1}\binom{3}{2} + \binom{4}{1}=40$$

EDIT :

A shortcut is to realize the list has three partitions of type $$aabc$$ and one of type $$aaab$$. Hence $$3\cdot \frac{4!}{2!}+4=40$$

• Thank you for your answer! This maybe the easiest solution for students to understand. Commented Dec 21, 2021 at 14:41

Using more powerful technique, for much more tough questions :

Lets use generating functions, lets assume that $$x's$$ mean apples and $$y's$$ mean pears, then a child can have at most $$3$$ apples or pears. Hence the generating function of each child is $$(x^3+ x^2y +xy^2 +y^3) = \frac{x^4 -y^4}{x-y}$$

Now , we need to find the coefficient of $$x^7y^5$$ in the expansion of $$(x^3+ x^2y +xy^2 +y^3)^4=\left( \frac{x^4 -y^4}{x-y} \right)^4$$

The answer is $$40$$.

• Thank you for your answer! I was always fascinated with the application of generating functions but I am still trying to grasp it. We raise the polynomial into the 4th power because we have four kids, am I right? Commented Dec 21, 2021 at 14:40
• @Vasya you are welcome ! I glad to help.. yes you are right ,because of that reason , we raised it by $4$ Commented Dec 21, 2021 at 16:54