Lollies

A shop sells 7 types of lollies. How many ways are there to arrange 14 lollies (bought from the shop) in a straight line if it is known that there is at least one of each of the 7 types among them?

Note: Lollies of the same type are indistinguishable.


The answer is 248619571200.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Miles Koumouris
Dec 1, 2017

Let f ( n , k ) f(n,k) denote the number of ways there are to arrange n n lollies bought from a shop that sells k k types of lollies in a straight line, given that there is at least one of each of the k k types among them. There are a few ways to see that

f ( n , k ) = i = 0 k ( 1 ) i ( k i ) ( k i ) n . f(n,k)=\sum_{i=0}^k(-1)^i\binom{k}{i}(k-i)^n.

One of which involves considering the number of ways there are to arrange n n lollies of k k types in a line with no restrictions, and then accounting for over/undercounting (i.e., the Inclusion-Exclusion Principle). Substituting n = 14 n=14 and k = 7 k=7 yields an answer of 248619571200 \boxed{248619571200} .

There are a few ways to see that f ( n , k ) = i = 0 k ( 1 ) i ( k i ) ( k i ) n . f(n,k)=\sum_{i=0}^k(-1)^i\binom{k}{i}(k-i)^n.

Can you share with us what these few ways are?

Pi Han Goh - 3 years, 6 months ago

Log in to reply

Sorry for the belated response!

Consider the number of ways there are to arrange n n lollies of k k types in a line with no restrictions; there are exactly k n k^n ways. This is not the answer however, since we have over-counted by including arrangements wherein not all k k types are present. There are exactly ( k 1 ) ( k 1 ) n \binom{k}{1}(k-1)^n arrangements for which there is at most k 1 k-1 types present. Subtracting this value is under-counting however, since several arrangements will have been counted multiple times in the subtraction due to the fact that it is not a requirement to have all the k 1 k-1 types present. One of these over-subtracted invalid arrangements can have at most k 2 k-2 types present, and hence there are ( k 2 ) ( k 2 ) n \binom{k}{2}(k-2)^n invalid arrangements where there are at most k 2 k-2 types present, which can be added.

Continuing in this manner, we see that we have re-included cases where there are from 0 0 to k 3 k-3 types present, and we can continue the process of alternately adding and subtracting these terms to yield

f ( n , k ) = i = 0 k ( 1 ) i ( k i ) ( k i ) n . f(n,k)=\sum_{i=0}^k(-1)^i\binom{k}{i}(k-i)^n.

That is probably the most direct argument, and it could be formalised by using the Inclusion-Exclusion Principle (as Mark has done in the solution below). It's also possible (but probably unlikely) to spot that

f ( n , k ) = k ! S n ( k ) f(n,k)=k!\mathcal{S}_n^{(k)}

if one knew enough about Stirling numbers of the second kind . From this follows a few alternative forms of f ( n , k ) f(n,k) including some recursive relations, and of course the formula we previously found. A more straightforward recurrence relation (like the one used by Tan Wei Xin in a solution below) makes it easy to calculate the value with a computer.

Miles Koumouris - 3 years, 6 months ago

Log in to reply

Oh this is wonderful! Thanks for sharing.

Pi Han Goh - 3 years, 6 months ago

I don't get it: I tried to arrange the lollies as follows:

  • Place 7 7 lollies, one of each type, in the 1 1 4 spots to guarantee the problem's condition: There are 14 14 ways to place the first, 13 13 to place the second, etc... This gives 14 × 13 × 12 × 11 × 10 × 9 × 8 14\times13 \times12 \times11 \times10 \times9 \times8 ways. The condition is now completed.

  • There are now 7 7 candies to put in 7 7 spots, with no restrictions: (This is also mentioned in the solution). This gives 7 7 candies to choose from for the first spot, 7 7 candies to choose from for the second spot, etc... This gives 7 7 7^7 ways to do this.

The total number of ways I got was 14 × 13 × 12 × 11 × 10 × 9 × 8 × 7 7 = 14 , 245 , 053 , 863 , 040 14\times13 \times12 \times11 \times10 \times9 \times8 \times7^7 = \boxed{14,245,053,863,040} ...

I guess I missed something. Could anyone please explain this to me?

Filip Rázek - 3 years, 6 months ago

Log in to reply

You have over-counted; consider a case where the first two spots are the same type - you would've counted this twice, since either the first spot is one of the 7 different types, and the second spot is one of the unrestricted remaining lollies that happens to be the same colour, or the first spot is one of the unrestricted remaining lollies that happens to be the same colour, and the second spot is one of the 7 different types.

Miles Koumouris - 3 years, 6 months ago

Log in to reply

Yep you are right. Now I see. Thanks!

Filip Rázek - 3 years, 6 months ago

I know that over counting is occurring here but I am not able to understand how. Can you please elaborate more on this? I mean the part where over counting occurs..

Vighnesh Raut - 3 years, 5 months ago
Mark Hennings
Dec 2, 2017

We are interested in the number of surjective functions from a set X X of size m m to a set Y = { 1 , 2 , 3 , . . . , n } Y = \{1,2,3,...,n\} of size n n . For any 1 j n 1 \le j \le n , let A j A_j be the set of functions from X X to Y Y for which j j is not in the range. Then A u 1 A u 2 A u r = ( n r ) m 1 u 1 < u 2 < < u r n |A_{u_1} \cap A_{u_2} \cap \cdots \cap A_{u_r}|\; = \; (n-r)^m \hspace{2cm} 1 \le u_1 < u_2 < \cdots < u_r \le n for any 1 r n 1 \le r \le n and so, by the Inclusion-Exclusion Principle, A 1 A 2 A n = r = 1 n ( 1 ) r 1 ( n r ) ( n r ) m |A_1 \cup A_2 \cup \cdots \cup A_n| \; = \; \sum_{r=1}^n (-1)^{r-1}\binom{n}{r} (n-r)^m and so the number of surjective functions is ( A 1 A 2 A n ) = n m A 1 A 2 A n = r = 0 n ( 1 ) r ( n r ) ( n r ) m |(A_1 \cup A_2 \cup \cdots \cup A_n)'| \; = \; n^m - |A_1 \cup A_2 \cup \cdots \cup A_n| \; = \; \sum_{r=0}^n (-1)^{r}\binom{n}{r} (n-r)^m Putting m = 14 m=14 and n = 7 n=7 gives the desired answer of 248619571200 \boxed{248619571200} .

Aman Dubey
Dec 7, 2017

Let each type of lollies are numbered as 1,2,3,4,5,6,7. Now let we select x i x_i lollies from i t h ith type. So that

x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 = 14 x_1+x_2+x_3+x_4+x_5+x_6+x_7=14 (*)

We see that each integral solution of this corresponds to a way of selection of lollies.

ie if x 1 = 12 , x 2 = 2 x_1=12, x_2=2

this means we select 12 lollies of type 1 and 2 lollies of type 2. For this particular selection the number of ways of arranging the lollies in a line is 14 ! 12 ! 2 ! \frac{14!}{12!2!} .

So what we wish to count is the sum of

14 ! x 1 ! x 2 ! x 3 ! x 4 ! x 5 ! x 6 ! x 7 ! \frac{14!}{x_1!x_2!x_3!x_4!x_5!x_6!x_7!}

for all solutions of (*).

So we can see that an exponential generating function can help us do that.

the generating function for this is

( x + x 2 2 ! + x 3 3 ! + . . . ) 7 = ( e x 1 ) 7 ( x+\frac{x^2}{2!}+\frac{x^3}{3!}+...)^7 =(e^x-1)^7

and our answer is then 14 ! ( 14!*( coefficient of x 14 ) x^{14}) which is 248619571200 \boxed{248619571200}

Can you please explain how do you get the exponential generating function?

Vighnesh Raut - 3 years, 5 months ago

Log in to reply

We want the sum of product of all x i ! x_i! 's in denominator. Also that all x i x_i 's appear as the power of x x inside each bracket. So what we do is simply take coefficient of x i x^i as 1 x i ! \frac{1}{x_i!} .

Aman Dubey - 3 years, 5 months ago
Abel McElroy
Feb 18, 2018

If we say each candy is a part of cycle within the greater set of 14 candies, then the problem stipulates that the we are counting the number of ways to partition a set of 14 elements into 7 cycles, which is S(14,7) However this count would ignore that each color is unique, so we must multiply S(14,7) by the number of ways to assign each of the seven colors to each of the cycles: 7!. S(14,7) * 7! = 248619571200

Tan Wei Xin
Dec 27, 2017

The way I solved this is by using dynamic programming.

Let the d p ( n , k ) dp(n,k) denote the number of ways to arrange the k k lollies with first n n colors such that at least one of each color is used. It's clear the recurrence relation is

d p ( i , j ) = k = i 1 j 1 d p ( i 1 , k ) ( j j k ) { dp }(i,j)=\sum _{ k=i-1 }^{ j-1 }{ { dp }(i-1,k)\left( \begin{matrix} j \\ j-k \end{matrix} \right) }

Once we have this recurrence relation we can simply calculate bottom-up until we reach d p ( 7 , 14 ) = 248619571200 dp(7,14) = \boxed{248619571200} .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...