To get a recursive relation for this type of problem Twelve square sheets are placed in a row, and each can be painted with one of the four colors Y,R,O,B. Find the number of ways this can be done so that each block of five adjacent sheets contains at least one sheet of each color . What i tried is that for lower cases of sheets i tried to see the pattern so as to motivate for a recursive relation but going from 7 to 8 case and higher ones needed a recursive relation which i am not able to generate . As lower cases (<8) dont need any recursion it can be easily solved.
 A: Let $n  \geqslant  5$ be the number of colored sheets, numbered from $1$ to $n$. We extend the system by adding a new sheet in position $0$ and shifting the sheets to the right.
For any coloring $c$, let the repetition index $r \in  \left\{2 , 3 , 4 , 5\right\}$ be
the index of the first sheet with a repeated color. If $r = 5$, it means that the $4$ first sheets have different colors. One can add a new sheet of any of the four colors, it gives $4$ ways to extend the coloring, which respective repetition indexes are $2 , 3 , 4 , 5$.
If $r < 5$, it means that there are only $3$ colors among the
$4$ first sheets and the only way to extend the system is to add a new
sheet which color is the missing color among the $3$. The result is
a coloring which repetition index is $r+1$.
Let ${X}^{\left(n\right)} = {\left({X}_{2}^{\left(n\right)} , {X}_{3}^{\left(n\right)} , {X}_{4}^{\left(n\right)} , {X}_{5}^{\left(n\right)}\right)}^{T}$
be the numbers of coloring with repetition indexes $\left(2 , 3 , 4 , 5\right)$ for
$n$ sheets. The previous reasoning shows that
\begin{equation}
{X}^{\left(n+1\right)} = A {X}^{\left(n\right)} = \left[\begin{array}{cccc}0&0&0&1\\
1&0&0&1\\
0&1&0&1\\
0&0&1&1
\end{array}\right] {X}^{\left(n\right)}
\end{equation}
In particular, the number ${C}_{n}$ of colorings of $n$ sheets is
${C}_{n} = U {X}^{\left(n\right)}$ where $U = \left(1 , 1 , 1 , 1\right)$. It follows that
\begin{equation}
{C}_{n+k} = U {A}^{k} {X}^{\left(n\right)}
\end{equation}
We claim that $U {A}^{k} = \left({u}_{k-3} , {u}_{k-2} , {u}_{k-1} , {u}_{k}\right)$ where the real sequence ${u}_{k}$ satisfies the recurrence relation
\begin{equation}
\boxed{{u}_{k+1} = {u}_{k}+{u}_{k-1}+{u}_{k-2}+{u}_{k-3}}
\end{equation}
Indeed, this is an immediate consequence of the relation
$U {A}^{k+1} = U {A}^{k} A$. The initial values of $u$ are
\begin{equation}
{u}_{{-3}} = {u}_{{-2}} = {u}_{{-1}} = {u}_{0} = 1
\end{equation}
It follows that
\begin{equation}
{C}_{n+k} = {u}_{k-3} {X}_{2}^{\left(n\right)}+{u}_{k-2} {X}_{3}^{\left(n\right)}+{u}_{k-1} {X}_{4}^{\left(n\right)}+{u}_{k} {X}_{5}^{\left(n\right)}
\end{equation}
For $n = 5$, one has ${X}^{\left(5\right)} = 4 ! \left(1 , 2 , 3 , 4\right)$, hence the formula
\begin{equation}
\boxed{{C}_{5+k} = {24}\times{\left(4 {u}_{k}+3 {u}_{k-1}+2 {u}_{k-2}+{u}_{k-3}\right)}}
\end{equation}
In particular ${C}_{12} = {24}\times{1129} = 27096$
Remark: note that $A$ has the form of a Companion matrix
