There are four types of legitimate sequence of length $n$:
Type $A$: the last four colours are distinct,
Type $B$: the second from last colour is repeated later in the sequence,
Type $C$: the third from last colour is repeated later in the sequence,
Type $D$: the fourth from last colour is repeated later in the sequence.
A length $n$ sequence of type $A$ may be extended uniquely to one sequence each of type $A,B,C,D$ of length $n+1$. Sequences of the other types may be extended uniquely to just one sequence of length $n+1$ of the following types:$$B\to C\to D\to A.$$
Let $A_n,B_n,C_n,D_n$ denote the number of length $n$ sequences of type $A,B,C,D$ respectively, each divided by 24 (to keep the numbers small). From the above we have:
\begin{eqnarray*}
A_{n+1}&=&A_n+D_n\\
B_{n+1}&=&A_n\\
C_{n+1}&=&A_n+B_n\\
D_{n+1}&=&A_n+C_n\\
\end{eqnarray*}
Writing $A_n,B_n,C_n,D_n$ as a column vector and starting at $n=4$ we get:
$$
\left(\begin{array}{c}
1\\1\\2\\3
\end{array}
\right)
\to
\left(\begin{array}{c}
4\\1\\2\\3
\end{array}
\right)
\to
\left(\begin{array}{c}
7\\4\\5\\6
\end{array}
\right)
\to
\left(\begin{array}{c}
13\\7\\11\\12
\end{array}
\right)
\to
\left(\begin{array}{c}
25\\13\\20\\24
\end{array}
\right)
\to
\left(\begin{array}{c}
49\\25\\38\\45
\end{array}
\right)
\to
\left(\begin{array}{c}
94\\49\\74\\87
\end{array}
\right)
$$
Adding the values for $n=10$ and returning the factor of 24 we get:$$24(94+49+74+87)=24*304=7296.$$
This was quick to do by hand for $n=10$. However the general solution will be a linear combination of $n$'th powers of the roots of the polynomial $$t^4-t^3-t^2-t-1.$$
Your answer is correct: to visualize this, let's use bars ($|$) to symbolize the baskets and plusses ($+$) to symbolize our possible choices.
We have six baskets, and we want to find how many ways we can select a set of consecutive baskets to put the apples in, given that there must be at least one basket with apples in it.
Consider the following arrangement of bars and plusses: $||+||+||$. We could take this to mean that the baskets inside the plusses will get apples and the rest will get oranges. The baskets inside the plusses will always be consecutive, so as long as we don't place our two plusses in the same location, we will meet both requirements.
There are $7$ possible spots for the plusses (we include the ends outside the bars) and we need to place $2$ plusses without replacement, and the order doesn't matter, so our final answer is $\binom{7}{2}$.
Best Answer
Since this task comes from programming contest, please update the post by giving the limits on $x$ and $y$.
Let's define a dynamic programming function $F[i][j][0/1]$. Where $F[i][j][0]$ is the number of ways to arrange $i$ A's and $j$ B's, the number $0$ means that the last letter in the arrangement is A. Similarly, $F[i][j][1]$ means the same while the $1$ shows us that the last letter is B.
The base cases would be $F[1][0][0] = 1, F[0][0][0 \text{ or } 1] = 1, F[0][1][1] = 1$.
For the transitions consider adding $d$ letters to the end, make sure that $d < k$ $$F[i][j][0] = F[i-1][j][1] + F[i-2][j][1] + ... + F[i-(k-1)][j][1]\\F[i][j][1] = F[i][j-1][0] + F[i][j-2][0] + ... + F[i][j-(k-1)][0]$$
The result is $F[x][y][0] + F[x][y][1]$. The computational complexity of the algorithm would be $O(x \cdot y \cdot K)$