Problem Description:
Divide a circle into n small slices, marking these slices as 1,2,3,..., N. Now use the M color to paint each sector, each with a color and a different fan color.
Ask: How many coloring methods are available.
Note: Do not consider numerical bounds. n>=1,m>=3;
Analysis:
Set a (n) a (n) as the sum of the painting methods that meet the required NN sector.
For fan 1, there are m coloring methods, fan 2 has m-1m-1 painting method, Fan 3 also has m-1m-1 coloring method, Fan n also has m-1m-1 coloring method. As a result, there are different coloring methods for a total MX (m−1) (n−1) MX (m−1) (n−1), but this coloring method may appear to be 1 identical to n, which is not the case, and should therefore be from MX (m−1) (n−1) MX (m−1) Subtract the painting methods that don't fit the requirements. How to calculate the painting method that does not conform to the requirements. 1 and N as a sector, the painting method is equivalent to using M color to n-1 a fan, that is, a (n−1). The recurrence relationship is as follows:
A (n) =m∗ (m−1) (n−1) −a (n−1), n>=3
def paint (M, n):
If n = 1: return
m
elif n = 2: Return
m* (m-1) return
m* (m-1) ^ (n-1)-Paint (M , n-1)