TITLE: Ways to number a row of trees
QUESTION [5 upvotes]: On the median strip of an infinite road there are n trees in a row. We want to mark all of them with the three numbers 1, 2 and 3, in such a way that all trees have one number and no two adjacent trees can have the same number. In how many ways is this possible, if one of the numbers (say, 3) must be used at least twice?
I tried to find a recursive relation by starting from the small numbers:
For $n=4$ I found that only 4 numberings are possible.
For $n=5$, I got 34 and for $n=6$, 88. I think the general formula for all possible numberings without the exclusion of the ones which have only 1 or 2 3's, is $3*2 ^{n-1}$ but I don't know how to calculate the invalid numberings.
Any help?

REPLY [4 votes]: Hint: disregarding the requirement for $3$ to be used at least twice, there would be $3 \cdot 2^{n-1}$ ways.  Now subtract the number of ways with $0$ or $1$ $3$'s.  Each configuration with no $3$'s consists of alternating $1$'s and $2$'s.  Each configuration with one $3$ consists either of a $3$ followed by alternating $1$'s and $2$'s, or alternating $1$'s and $2$'s followed by a $3$ and then (if there are some trees left) alternating $1$'s and $2$'s.