How many ways can 12 candies be distributed among 4 children so that each child gets 3 candies?

I am taking a Coursera course called "combinatorics and probability". The following question was a practice quiz question:

There are 15 identical candies, how many ways are there to distribute them among 7 kids?

In the lecture proceeding the quiz, the instructor briefly revealed that the correct answer is:nCr(21,6) == 54,264 but I do not understand why that is the case. I was thinking that since each piece of candy is identical and they must be distributed among 7 kids, that you could just do 7^15.

What am I not understanding here?

Seven distinct pieces of candy are to be distributed among three bags. The red bag and the blue bag must each receive at least one piece of candy; the white bag may remain empty. How many arrangements are possible?

Solution 1

We can count the total number of ways to distribute the candies (ignoring the restrictions), and then subtract the overcount to get the answer.

Each candy has three choices; it can go in any of the three bags.

Since there are seven candies, that makes the total distribution


To find the overcount, we calculate the number of invalid distributions: the red or blue bag is empty.

The number of distributions such that the red bag is empty is equal to , since it's equivalent to distributing the candies into bags.

We know that the number of distributions with the blue bag is empty will be the same number because of the symmetry, so it's also .

The case where both the red and the blue bags are empty (all candies are in the white bag) are included in both of the above calculations, and this case has only distribution.

The total overcount is


The final answer will be

Solution 2

We can use to our advantage the answer choices has given us, and eliminate the obvious wrong answers.

We can first figure out how many ways there are to take two candies from seven distinct candies to place them into the red/blue bags: .

Now we can look at the answer choices to find out which ones are divisible by , since the total number of combinations must be multiplied by some other number.

Since answers A, B, D, and E are not divisible by 3 (divisor of 42), the answer must be .

Solution 3

Let be the number of red bag candies. For .

So the number of candies left for the blue bag and the red bag is . Based on the problem, 1 candy must be fixed for the blue bag, which can be done ways. Now, before we continue, we need to realize that fixing a candy can lead to some over counting in cases where none in the white bag overlap. So we should try and find an alternative because we'll be over counting more than twice, and that will become extremely difficult to account for each case's over counting.

So, without fixing candies, we can put everything into options and work on the white bag, because once we figure out two bags, the remaining one is decided.

The options for the candies in the white bag are two: In the white bag or out of the white bag(by default, in the blue bag).

Now, for choosing the red bag, we have .

Then, we have for the white bag: . Because we aren't fixing one for blue, the power is instead of

We have: Adding them up for , we get 2058.

Now, for the invalid cases. Because we didn't fix candy for the blue bag, we need to subtract the cases where the blue bag remains empty. We can accomplish this pretty easily.

When , how many ways can the remaining 1 candy be placed in the blue bag. This can be done ways.

When , how many ways can the remaining 2 candies be placed in the blue bag. This can be done ways.

When , how many ways can the remaining 3 candies be placed in the blue bag. This can be done ways.

And because , we just multiply by two.

Finally, we have:

~Raghu9372

Video Solution

//youtu.be/ZfnxbpdFKjU?t=195

~IceMatrix

Video Solution

//youtu.be/8WrdYLw9_ns?t=739

~ pi_is_3.14

See also

The problems on this page are copyrighted by the Mathematical Association of America's American Mathematics Competitions.

I would recommend that you avoid too many nested conditions and loops. And is there a reason why you want your answer to involve a list comprehension? I like using them too, but beyond a point they become too long to, um... comprehend. Here's an alternative solution that uses fewer loops, avoids long list comprehensions and is easier to read -- to my eyes, at least.

In [29]: from itertools import permutations, combinations_with_replacement In [30]: def all_valid_permutations(candies, members): ...: combos = combinations_with_replacement(range(1, candies), members) ...: valid_permutations = set() ...: for item in combos: ...: for perm in permutations(item): ...: if sum(perm) == candies and len(set(perm)) >= members-1: ...: valid_permutations.add(perm) ...: ...: return valid_permutations ...: In [31]: all_valid_permutations(6, 3) Out[31]: {(1, 1, 4), (1, 2, 3), (1, 3, 2), (1, 4, 1), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1), (4, 1, 1)}

If you know your basic combinatorics you can guess what the imported functions do. (Or you can read the docs, if you prefer.) I can't guarantee performance, though, without fully knowing your use-case. This is just a quick solution, off the top of my head. I bet you can optimise this further.

Última postagem

Tag