The word DOLL has length $4$. There will be $18$ possible positions where 'DOLL' can appear, each with $3^{17}$ choices. So there will $18 \cdot 3^{17}$ cases where it can appear at least once. But I also know that there will be many duplicates in this approach. How do I go about removing them.
I can count those
- With DOLL appearing at least / only $5$ times as $\binom{6}{5}$ each with $3^{21-4 \cdot 5} = 3$ choices.
- With DOLL appearing at least $4$ times as
- $21$ positions to place DOLL first time
- $17$ positions to place DOLL second time
- $13$ positions to place DOLL third time
- $9$ positions to place DOLL fourth time
- all with $3^{5}$ choices, so this gives $21 \cdot 17 \cdot 13 \cdot 9 \cdot 3^5$ possibilities
- if I subtract all the choices that have $5$ occurrences of DOLL ($\binom{6}{5} \cdot 3$)from this, I will get only those that have $4$ occurrences of DOLL
But from here on how do I proceed for calculating $3$, $2$ and only $1$ occurrences. Do I apply the inclusion exclusion principle at each step or only when calculating for at most $1$ occurrence of DOLL.
"DOLL" can't self-overlap, so you can consider each occurrence of it as a separate block. There are $3^{21-4k}$ strings with "DOLL" in $k$ particular places, and $\binom{21-3k}k$ ways to choose the $k$ places, so by inclusion-exclusion there are
$$ \sum_{k=1}^5(-1)^{k-1}\binom k1\binom{21-3k}k3^{21-4k}=2002583502 $$
strings that contain "DOLL" exactly once.