Example 2 Color each vertex of a square pyramid with one color, and make the endpoints of the same edge have different colors. If only 5 colors are available, then the total number of different coloring methods is
Solution
Solution: Vertex can be colored with any of the colors, and the color on cannot appear on the vertices of the polygon . The problem is then reduced to coloring the vertices of the polygon with colors, ensuring that adjacent vertices have different colors. Let there be ways to do this. Then,
For , consider the recurrence relation for . If starting from , then has ways to be colored, and each have ways to be colored, and finally to , if only requiring to be different from , there are still ways to color it. Thus, there are
ways in total. However, this calculation can be divided into two categories: one where is different from , which meets the requirement and is exactly ways; the other where is the same as , which does not meet the requirement, but by merging and into one point, we get ways. Therefore,
Transforming and recursively,
Thus, .
Therefore, the total number of coloring methods for the entire pyramid is
In particular, for , we get
Here, we see the shadow of an old problem: dividing a circular surface into sectors, denoted as . Each sector can be colored with one of the three different colors: red, white, and blue, with the requirement that adjacent sectors have different colors. How many coloring methods are there?