In how many ways can we colour $n$ baskets with $r$ colours? In how many ways can we colour $n$ baskets using up to $r$ colours such that no two consecutive baskets have the same colour and the first and the last baskets also have different colours?
For example, if we take $N=5$ and $r = 4$, and represent the colours by $R,B,Y$ and $G$, then $\langle R,Y,B,G,Y\rangle$ is a valid arrangement whereas $\langle R,R,B,G,Y \rangle$ and $\langle G,B,R,Y,G\rangle$ aren't.
It's is not difficult to solve this one by brute force; however, I would like to see a combinatorial approach. Any thoughts?
 A: Let $a_n$ be the number of arrangements in which the first and last basket have different colours, and $b_n$ the number of arrangements in which they have the same colour, where in either case adjacent baskets can't have the same colour. Then by adding an admissible basket at the end of such an arrangement we obtain the recurrence
$$
\begin{align}
a_{n+1}&=(r-2)a_n+(r-1)b_n\;,\\
b_{n+1}&=a_n\;,
\end{align}
$$
and substituting the second equation into the first yields
$$
a_{n+1}=(r-2)a_n+(r-1)a_{n-1}\;.
$$
The characteristic equation is
$$
\lambda^2-(r-2)\lambda-(r-1)=0\;,
$$
with solutions $\lambda=-1$ and $\lambda=r-1$. Thus we have
$$
a_n=c_1(-1)^n+c_2(r-1)^n\;,
$$
and the initial conditions $a_1=0$ and $a_2=r(r-1)$ yield
$$
-c_1+c_2(r-1)=0\;,\\
c_1+c_2(r-1)^2=r(r-1)
$$
with solution $c_1=r-1$, $c_2=1$. The desired number of arrangements is therefore
$$
a_n=(-1)^n(r-1)+(r-1)^n\;.
$$
To get the number of arrangements that use all $r$ colours, you can use inclusion/exclusion:
$$
\sum_{k=0}^r(-1)^{r-k}\binom rk\left((-1)^n(k-1)+(k-1)^n\right)\;,
$$
and the sum over the first term vanishes, leaving
$$
\sum_{k=0}^r(-1)^{r-k}\binom rk(k-1)^n\;.
$$
A: Let $U$ be the set of all $r^n$ possible colourings of the $n$ baskets with $r$ colours. For $i=1,2,\ldots,n$ let $A_i$ be the subsets of of such colourings where basket $i$ has the same colour as basket $i+1$ (taking the latter to be basket $1$ for $i=n$); we want to count the number of colourings in the complement in $U$ of $\bigcup_{i=1}^nA_i$, in other words those that lie in none of the sets $A_i$.
For each set $A_i$, by requiring the colours of a given pair of baskets to be the same, we are left with a free choice of $n-1$ baskets to colour (one for the pair, and $n-2$ other baskets) with $r$ colours, so each $A_i$ has size $r^{n-1}$. More generally for $k<n$, the intersection of $k$ among the sets $A_i$ restrains the choice of $k$ baskets, so leaves $n-k$ baskets to be coloured freely; the intersection contains $r^{n-k}$ colourings. For $k=n$ this would not be right, since already the intersection of $n-1$ of the sets $A_i$ contains the $r^1=r$ monochromatic colourings, and the intersection of that with the final set $A_i$ does not change the intersection; therefore we get $r^1=1$ rather that $r^0=1$ as the size of the intersection of all the sets $A_i$.
If we define the intersection of none of the sets $A_i$ to be the entire set $U$, the principle of inclusion/exclusion tells us that
$$
\#\left(U\setminus\bigcup_{i=1}^nA_i\right) = \sum_{k=0}^n(-1)^k\sum_{P\in\binom{\{1,2,\ldots,n\}}k}\#\left(\bigcap_{i\in P}A_i\right).
$$
We have argued that the size of the final intersection does not depend on the choice of the set$~P$ of $k$ indices$~i$, but only on $k$; calling this size $s(k)$ our answer will be
$$
\#\left(U\setminus\bigcup_{i=1}^nA_i\right) = \sum_{k=0}^n(-1)^k\binom{n}ks(k).
$$
Finally we saw that $s(k)=r^{\max(n-k,1)}$ (which indeed for $k=0$ gives the size $r^n$ of $U$), so we get
$$
\sum_{k=0}^n(-1)^k\binom{n}ks(k)
=\sum_{k=0}^n(-1)^k\binom{n}kr^{\max(n-k,1)}
\\=\left(\sum_{k=0}^n(-1)^k\binom{n}kr^{n-k}\right) +(-1)^n (r-1)
\\=(r-1)^n+(-1)^n (r-1)
$$
where we realised we had almost an instance of the binomial formula for $(r-1)^n$.
