I have 12 indistinguishable candies, which need to be wrapped in some indistinguishable , transparent plastic bags in the following way:
After wrapping up all the candies, I arrange the plastic bags in a line, however, I don't want the last bag to contain 9 or more candies.
How many different ways of lining up those bags are there?
This problem is a part of <Christmas Streak 2017> series.
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.
Let f ( n , k ) denote the number of ways to wrap the first n candies where if k = 0 , then no bag contains exactly 2 candies, otherwise k = 1 .
We have
f ( n , 0 ) = ( i = n − 1 ∑ 0 f ( i , 0 ) ) − f ( n − 2 , 0 ) = f ( n − 1 , 0 ) + f ( n − 2 , 0 ) + f ( n − 4 , 0 )
Thus we can easily calculate up to f ( 1 2 , 0 ) .
Moreover, we have
f ( n , 1 ) = ( i = n − 1 ∑ 0 f ( i , 1 ) ) + f ( n − 2 , 0 ) = 2 f ( n − 1 , 1 ) + f ( n − 2 , 0 ) − f ( n − 3 , 0 )
Thus we can also easily calculate up to f ( 1 2 , 1 ) .
f ( 1 2 , 1 ) included the cases where the size of last bag is ≥ 9 , so we simply need to subtract f ( i , 1 ) where 0 ≤ i ≤ 3 to get the desired answer, which is
1 6 9 7 − 0 − 0 − 1 − 2 = 1 6 9 4
Let N n be the number of ways of bagging and lining up n candies, if we do not have to worry about having a bag containing two candies. Then N 0 = 1 and, thinking about the number j of candies in the first bag in the line, we have N n = j = 1 ∑ n N n − j = k = 0 ∑ n − 1 N k It is a simple induction to show that N n = { 2 n − 1 1 n ≥ 1 n = 0 Now let T n be the number of ways of bagging and lining up n candies, if at least one of the bags has to contain two candies. Then T 0 = T 1 = 0 , T 2 = 1 . Thinking about the number j of candies in the first bag in the line, we see that T 3 T 4 T 5 T n = T 2 + N 1 + T 0 = T 3 + N 2 + T 1 + T 0 = T 4 + N 3 + T 2 + T 1 + T 0 = j = 1 ∑ n T n − j + ( N n − 2 − T n − 2 ) Once we have a bag with two candies in it, we do not have to keep on looking out for two-candy bags, and so we replace T n − 2 by N n − 2 .
Iterating this recurrence relation, we obtain T 3 = 2 , T 4 = 4 , T 5 = 9 , T 6 = 2 0 , T 7 = 4 3 , T 8 = 9 1 , T 9 = 1 9 1 , T 1 0 = 3 9 8 , T 1 1 = 8 2 4 and T 1 2 = 1 6 9 7 .
Of the T 1 2 ways of bagging and lining up twelve candies, three of these, ( 1 , 2 , 9 ) , ( 2 , 1 , 9 ) , ( 2 , 1 0 ) , have nine or more candies in the last bag. Thus the answer is 1 6 9 4 .
Problem Loading...
Note Loading...
Set Loading...
First off, how many ways are there if I didn't have a girlfriend and didn't care about the last bag?
Let's define the number of ways of doing this for n candies as a n .
Of course a 0 = 1 and a 1 = 1 .
Let's consider the last bag of candies. There can be n , ( n − 1 ) , ( n − 2 ) , ⋯ , 3 , 2 , or 1 candies in that bag.
Then completing the rest of the bags would equal a 0 + a 1 + a 2 + a 3 + ⋯ + a n − 3 + a n − 2 + a n − 1 .
So a n = k = 1 ∑ n − 1 a k . Solving this yields a n = 2 a n − 1 , proving that this sequence is geometric.
Therefore a n = 2 n − 1 ( n ≥ 2 ) , and the number of ways of doing this is a 1 2 = 2 1 1 = 2 0 4 8 .
Nextly, how many ways are there if I still didn't care about the last bag and was being a mean guy and didn't make any bags that contain 2 candies?
Let's define the number of ways of doing this for n candies as b n .
Of course b 0 = 1 and b 1 = 1 and b 2 = 1 .
Let's, again, consider the last bag of candies. There can be n , ( n − 1 ) , ( n − 2 ) , ⋯ , 5 , 4 , 3 , or 1 candies in that bag since we can't have 2 candies in a bag.
Then completing the rest of the bags would equal b 0 + b 1 + b 2 + b 3 + ⋯ + b n − 4 + b n − 3 + b n − 1 .
So b n = k = 1 ∑ n − 1 b k − b n − 2 . Solving this yields b n = 2 b n − 1 − b n − 2 + b n − 3 .
Computing with this linear recurrence relation, we get b 3 = 2 , b 4 = 4 , b 5 = 7 , b 6 = 1 2 , b 7 = 2 1 , b 8 = 3 7 , b 9 = 6 5 , b 1 0 = 1 1 4 , b 1 1 = 2 0 0 , b 1 2 = 3 5 1 .
Then from above, if I was a nice guy but didn't care about the last bag, there are 2 0 4 8 − 3 5 1 = 1 6 9 7 ways of doing this.
There are three possible cases that makes the last bag contain 9 or more candies: (1, 2, 9), (2, 1, 9), (2, 10).
And thus, the number of ways of doing this is 1 6 9 7 − 3 = 1 6 9 4 .