Recursive Formula

108 Views Asked by At

I have found a question in my book and I have solve it, but I am not sure about the answer.

The question goes like this:

Find a recursive formula that will give the number of ways to order $N$ ice cream balls of two types, Chocolate and Vanilla when 3 balls of Vanilla can't be ordered in a row.

The Answer:

$$f(n) =f(n-1)+f(n-2)+f(n-3)$$ $$f(1)=2 $$ $$f(2) = 4$$ $$f(3) = 7$$

1

There are 1 best solutions below

2
On BEST ANSWER

Yes, your answer is good.

A row of $N$ balls can be finished either by

  1. One last chocolate ball
  2. One (before last) chocolate ball and one last vanilla ball
  3. One (before two last) chocolate ball and two last vanilla balls.
  4. No other way

So You can obtain all rows of $N$ balls either by

  1. Take a row of $N-1$ balls and add a chocolate.
  2. Take a row of $N-2$ balls and add a chocolate and a vanilla.
  3. Take a row of $N-3$ balls and add a chocolate and two vanilla balls.

So you obtain your answer.