Fan painting problem (Python) __python

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.