Let f(n) be the number of combinations of length n with c colours. We then use the recurrence relationship: F(n)=C*(F(n-2)+F(n-3)) |
F(n) represents a string of length N. You can place any 1 color bead on that string... which will consume space on the string.
There are 2*C possible beads to place on the string. 2* because one set is of length 2 and one set is of length 3... resulting in 2 sets.
So you place 1 bead on the string... this reduces the length of N (available string space) by the size of the bead you placed. You then have another 2*C possibilities for the next bead.
Therefore:
F(n) = 2*C * F(n - size_of_last_bead)
But since the size of the last bead is variable... it's not that simple. Instead, we need to the two sizes differently.
So instead of saying we have 2*C possibilities... let's say we have C possibilities of length 2, and C possibilities of length 3:
F(n) = C*F(n-2) + C*F(n-3)
From there, you just factor out the C and you get the equation in your original post:
F(n) = C( F(n-2) + F(n-3) )
EDIT:
Although this solution is not complete because it does not account for the possibility of ending the string short (it assumes you will use as much of the string space as possible in your computations)
So the proper formula would probably be closer to this:
|
F(n) = 1 + C*F(n-2) + C*F(n-3)
|
But even that isn't quite right because doing F(n) with a negative number will not work, so you'd have to conditionally call F(n-2) and F(n-3)