A. CQXYM Count Permutations800 / 数学

Posted 幽殇默

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A. CQXYM Count Permutations800 / 数学相关的知识,希望对你有一定的参考价值。


https://codeforces.com/contest/1581/problem/A
最简单的方法就是看样例其实可以才出来结果就是(n*2)!/2 因为要对除法取余,故需要求逆元。
正解: 根据对称性可以得出,合法的答案和不合法的答案是平分所有的方案的。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
const int mod=1e9+7;
typedef long long int LL;
LL f[N];
void init() 
{
	f[0]=1,f[1]=1;
	for(int i=2;i<=1e5*2;i++) f[i]=(f[i-1]*i)%mod;
}
LL quick_mi(LL a,LL b,LL p)
{
	LL sum=1;
	while(b)
	{
		if(b&1) sum=(sum*a)%p;
		b>>=1;
		a=(a*a)%p;
	}
	return sum%p;
}
int main(void)
{
	int t; cin>>t;
	init();
	while(t--)
	{
		int n; cin>>n;
		cout<<f[n*2]*quick_mi(2,mod-2,mod)%mod<<endl;
	}
	return 0;
}

以上是关于A. CQXYM Count Permutations800 / 数学的主要内容,如果未能解决你的问题,请参考以下文章

1581 A. CQXYM Count Permutations(思维)

next_permutatio

Appium - adb monkey参数

2 0 2 0 年 第 十 一 届 蓝 桥 杯 - 省赛 - Python大学组 - A. 门牌制作

Lintcode15 Permutations solution 题解

delphi 如何保留小数