5. Label the 2014 small squares of a $1 \times 2014$ grid from left to right as $1,2, \cdots, 2014$. Now, use three colors $g, r, y$ to color each small square, such that even-numbered squares can be colored with any of $g, r, y$, while odd-numbered squares can only be colored with $g, y$, and adjacent squares must be of different colors. Then the number of ways to color this grid is .
5. $S_{2014}=4 \times 3^{1006}$.

Let $g_{n} 、 r_{n} 、 y_{n}$ represent the number of ways to color the $n$-th cell in a $1 \times n$ grid with colors $g 、 r 、 y$, respectively.
Then $\left\{\begin{array}{l}g_{1}=g_{2}=1, \\ r_{1}=0, r_{2}=2, \\ y_{1}=y_{2}=1,\end{array}\right.$

and $\square$
$\left\{\begin{array}{l}g_{n}=y_{n}, \\ g_{2 n+1}=y_{2 n}+r_{2 n}, \\ g_{2 n+2}=y_{2 n+1}, \\ r_{2 n-1}=0, r_{2 n}=g_{2 n-1}+y_{2 n-1} .\end{array}\right.$
Thus, $g_{2 n+1}=y_{2 n}+g_{2 n-1}+y_{2 n-1}=3 g_{2 n-1}$.
Also, $g_{1}=1$, so
$g_{2 n-1}=3^{n-1}=g_{2 n}$, and $r_{2 n}=2 \times 3^{n-1}$.
Let the total number of coloring methods be $S_{n}$. Then
$$
\begin{array}{l}
S_{2 n}=2 g_{2 n}+r_{2 n}=2 \times 3^{n-1}+2 \times 3^{n-1} \\
=4 \times 3^{n-1} .
\end{array}
$$

Therefore, $S_{2014}=4 \times 3^{1006}$.