【Codeforces 1433 E】Two Round Dances,排列组合,公式
problem
E. Two Round Dances
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1,3,4,2], [4,2,1,3] and [2,1,3,4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
one round dance — [1,2], another — [3,4];
one round dance — [2,4], another — [3,1];
one round dance — [4,1], another — [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n2 people.
Input
The input contains one integer n (2≤n≤20), n is an even number.
Output
Print one integer — the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
inputCopy
2
outputCopy
1
inputCopy
4
outputCopy
3
inputCopy
8
outputCopy
1260
inputCopy
20
outputCopy
12164510040883200
solution
/*
题意:
+ 给出长为n的序列(1...n),等分成两个环,求有几种分法。
思路:
+ 首先选n/2个人进第一组,方法数为C(n/2,n)。然后设定组内顺序,因为是环,所以有(n/2-1)!种,因为有两组所以要乘以2次。最后因为(x,y)和(y,x)等价,所以答案除以2。
+ 答案可以在OEIS上找到。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 110;
LL f[maxn];
int main(){
ios::sync_with_stdio(false);
int n; cin>> n;
f[0] = 1;
for(int i = 1; i <= n; i++)
f[i] = f[i-1]*i;
LL ans = f[n]/f[n/2]/f[n/2];
ans *= f[n/2-1];
ans *= f[n/2-1];
ans /= 2;
cout<<ans<<"\n";
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/113358886
- 点赞
- 收藏
- 关注作者
评论(0)