Count the Number of Arrays with K Matching Adjacent Elements
Choose which k neighbouring pairs match with a binomial coefficient, then multiply the m-1 choices for each pair that must differ.
Choose which k neighbouring pairs match with a binomial coefficient, then multiply the m-1 choices for each pair that must differ.