Christmas Streak 36/88: Wrapping Some Candies!

I have 12 indistinguishable candies, which need to be wrapped in some indistinguishable , transparent plastic bags in the following way:

  • I can use as many plastic bags as I want, but each bag must contain at least 1 candy.
  • I have to give my girlfriend two candies, so there must be at least one plastic bag containing 2 candies.

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.


The answer is 1694.

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.

3 solutions

Boi (보이)
Nov 4, 2017

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 n candies as a n . a_n.

Of course a 0 = 1 a_0=1 and a 1 = 1. a_1=1.

Let's consider the last bag of candies. There can be n , ( n 1 ) , ( n 2 ) , , 3 , 2 , n,~(n-1),~(n-2),~\cdots,~3,~2, or 1 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 . a_0+a_1+a_2+a_3+\cdots+a_{n-3}+a_{n-2}+a_{n-1}.

So a n = k = 1 n 1 a k . \displaystyle a_n=\sum_{k=1}^{n-1} a_k. Solving this yields a n = 2 a n 1 , a_n=2a_{n-1}, proving that this sequence is geometric.

Therefore a n = 2 n 1 ( n 2 ) , a_n=2^{n-1}~(n\ge2), and the number of ways of doing this is a 12 = 2 11 = 2048. a_{12}=2^{11}=2048.


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 n candies as b n . b_n.

Of course b 0 = 1 b_0=1 and b 1 = 1 b_1=1 and b 2 = 1. b_2=1.

Let's, again, consider the last bag of candies. There can be n , ( n 1 ) , ( n 2 ) , , 5 , 4 , 3 , n,~(n-1),~(n-2),~\cdots,~5,~4,~3, or 1 1 candies in that bag since we can't have 2 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 . b_0+b_1+b_2+b_3+\cdots+b_{n-4}+b_{n-3}+b_{n-1}.

So b n = k = 1 n 1 b k b n 2 . \displaystyle b_n=\sum_{k=1}^{n-1}b_k-b_{n-2}. Solving this yields b n = 2 b n 1 b n 2 + b n 3 . b_n=2b_{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 = 12 , b 7 = 21 , b 8 = 37 , b 9 = 65 , b 10 = 114 , b 11 = 200 , b 12 = 351. b_3=2,~b_4=4,~b_5=7,~b_6=12,~b_7=21,~b_8=37,~b_9=65,~b_{10}=114,~b_{11}=200,~b_{12}=351.


Then from above, if I was a nice guy but didn't care about the last bag, there are 2048 351 = 1697 2048-351=1697 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 1697 3 = 1694 . 1697-3=\boxed{1694}.

Tan Wei Xin
Dec 27, 2017

Let f ( n , k ) f(n,k) denote the number of ways to wrap the first n n candies where if k = 0 k=0 , then no bag contains exactly 2 2 candies, otherwise k = 1 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 ) \displaystyle f(n,0) = (\sum_{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 ( 12 , 0 ) f(12,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 ) \displaystyle f(n,1) = (\sum_{i=n-1}^{0}f(i,1)) + f(n-2,0) = 2f(n-1,1)+f(n-2,0)-f(n-3,0)

Thus we can also easily calculate up to f ( 12 , 1 ) f(12,1) .

f ( 12 , 1 ) f(12,1) included the cases where the size of last bag is 9 \ge 9 , so we simply need to subtract f ( i , 1 ) f(i,1) where 0 i 3 0 \le i \le 3 to get the desired answer, which is

1697 0 0 1 2 = 1694 1697 - 0 - 0 - 1 - 2 = \boxed{1694}

Mark Hennings
Nov 5, 2017

Let N n N_n be the number of ways of bagging and lining up n n candies, if we do not have to worry about having a bag containing two candies. Then N 0 = 1 N_0=1 and, thinking about the number j 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 N_n \; = \; \sum_{j=1}^{n}N_{n-j} \; = \; \sum_{k=0}^{n-1} N_k It is a simple induction to show that N n = { 2 n 1 n 1 1 n = 0 N_n \; = \; \left\{ \begin{array}{lll} 2^{n-1} & \qquad & n \ge 1 \\ 1 & & n= 0 \end{array} \right. Now let T n T_n be the number of ways of bagging and lining up n n candies, if at least one of the bags has to contain two candies. Then T 0 = T 1 = 0 T_0 = T_1 = 0 , T 2 = 1 T_2 = 1 . Thinking about the number j j of candies in the first bag in the line, we see that T 3 = T 2 + N 1 + T 0 T 4 = T 3 + N 2 + T 1 + T 0 T 5 = T 4 + N 3 + T 2 + T 1 + T 0 T n = j = 1 n T n j + ( N n 2 T n 2 ) \begin{aligned} T_3 & = \; T_2 + N_1 + T_0\\ T_4 & = \; T_3 + N_2 + T_1 + T_0\\ T_5 & = \; T_4 + N_3 + T_2 + T_1 + T_0 \\ T_n & = \; \sum_{j=1}^{n} T_{n-j} + (N_{n-2} - T_{n-2}) \end{aligned} 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 T_{n-2} by N n 2 N_{n-2} .

Iterating this recurrence relation, we obtain T 3 = 2 T_3 = 2 , T 4 = 4 T_4 = 4 , T 5 = 9 T_5 = 9 , T 6 = 20 T_6 = 20 , T 7 = 43 T_7 = 43 , T 8 = 91 T_8 = 91 , T 9 = 191 T_9 = 191 , T 10 = 398 T_{10} = 398 , T 11 = 824 T_{11} = 824 and T 12 = 1697 T_{12} = 1697 .

Of the T 12 T_{12} ways of bagging and lining up twelve candies, three of these, ( 1 , 2 , 9 ) (1,2,9) , ( 2 , 1 , 9 ) (2,1,9) , ( 2 , 10 ) (2,10) , have nine or more candies in the last bag. Thus the answer is 1694 \boxed{1694} .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...