【Codeforces 1433 E】Two Round Dances,排列组合,公式

举报
小哈里 发表于 2022/05/11 00:43:32 2022/05/11
【摘要】 problem E. Two Round Dances time limit per test1 second memory limit per test256 megabytes inputstand...

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

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。