Counting words with constraints is the topic of the problem in this note.

Your browser can't display this PDF inline. Open it directly.