Q. How many strings in {0,1,2,3} have an even number of 1's.
The answer provided uses the recurrence relation $a_{n+1} = 3a_n + (4^n - a_n)$.
The hint given was that consider the last string of length $n+1$ is :
$0$ - Number of strings that can proceed is $a_n$.
I'm assuming that $a_n$ is the number of legal strings that can follow $0$.
So if there was a string $02123210$, since this string has an even number of ones ($a_n$), then $a_n$ strings can proceed the previous string.
Then it would be the same for $2,3$ resulting in the $3a_n$. I don't know however how the $(4^n-a_n)$ came about.
I've tried looking at What is the recurrence relation in this problem?. Since it looks similar to this problem.
Suppose $a_n$ is the number of GOOD strings of length $n$. By GOOD we mean the strings that satisfies the given criterion (i.e it has even number of $1's$). Then consider a GOOD string of length $n+1$. It can be made in two ways:
The number of strings from case 1 will be $3a_n$ (because of $3$ choices of ending a GOOD string of length $n$).
The number of strings from case 2 will be = the number of BAD strings of length $n$. This is same as total strings of length $n$ - the number of GOOD strings of length $n$.
The total number of strings of length $n$ made up of four symbols is $4^n$ and the number of GOOD strings of length $n$ is $a_n$. Therefore the total number of BAD strings of length $n$ is $4^n-a_n$.
I hope this helps.