AOJ2025 Eight Princes

Source: Internet
Author: User

We look at the more general situation and set the number to M

Then n < m * 2 no solution

Then n is an odd number of cases:

We packed a person and a space, and left M "people" and n-m spaces, randomly arranging the "people", then inserting the blanks

The nature of the different "people" is arranged in the circumference (m-1)! For each arrangement, there are m positions inserted into n-m spaces, there are methods in C (N-m-1, m-1), and for an arrangement, the circumference is arranged with n

Ans = C (n-m-1, m-1) * (M-1)! * N

Finally, N is an odd number of cases:

We pack the opposite two points and then turn into a circle of length N/2

Equivalent to N/2 selected M, a continuous K-segment 1 scheme corresponding to the original 2k scheme

So ans = n/2 * (m-1)! *σ (2k * C (N/2-m-1, k-1) * C (M, K)) (where 1≤k≤m)

Then the topic compares the ghost animal ... I'd better be on the py ...

1 defC (N, m):2     if(N < m):return03     returnFac[n]/fac[m]/fac[n-m]4  5 defwork_odd (N, m):6     returnn * C (N-M-1, m-1) * fac[m-1]7  8 defWork_even (N, m):9res =0TenN/= 2 Onei =m A      while(I >0): -Res = (res + c (n-m-1, i-1) * C (M, i)) * 2 -I-= 1 the     returnRES * FAC[M-1] *N; -   -FAC = [1] * 105 -  forIinchRange (1, max): fac[i] = fac[i-1] *I +n =input () -m = 8 +  while(N >0): A     if(N < M * 2):Print0 at     elif(n% 2 = = 1):Printwork_odd (n, m) -     Else:PrintWork_even (n, m) -n = input ();
View Code

AOJ2025 Eight Princes

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.