Ternary Strings Avoiding 11 — Solution & Editorial
Build the KMP automaton for the forbidden pattern; states are the length of the current matched prefix. The transfer matrix (rejecting transitions that complete the pattern) raised to the N-th power counts safe strings.
Complexity: O(m3 log N)
Watch out: The automaton must use the KMP failure function so overlapping partial matches transition correctly.