Maths WorkshopMaths problems with full solutions
Exercise 877Combinatorics › Counting principlesL1Added 3 Nov 2026

Coloring problems

#coloring#product rule#recurrence

Statement

In how many ways can we color nn squares in a row with kk colors such that no two adjacent squares share a color?

Hint

First square has kk choices; each subsequent has k−1k-1.

Show solutionHide solution

Solution

Product. First square: kk choices. Each of the remaining n−1n-1 squares: k−1k-1 choices (must differ from the previous).

Total. k(k−1)n−1k(k-1)^{n-1}.

Conclusion. k(k−1)n−1k(k-1)^{n-1} colorings.