栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

1581 A. CQXYM Count Permutations

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1581 A. CQXYM Count Permutations

题目


思路

如果一个长度为 2 n 2n 2n的数组中存在至少 n n n对 p i < p i + 1 p_i 因为全排列是对称的,所以当1 2 3 4符合要求的是后,把他倒过来4 3 2 1肯定不符合条件,因此答案就是 2 n 2n 2n的全排列再除 2 2 2,即 ! ( 2 n ) / 2 !(2n)/2 !(2n)/2
注意在除2的时候要使用逆元=

代码
#include
#include
#include
#include
#include
#include
#define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long LL;

LL f[N * 2];

void ff() {
	f[1] = 1;
	for (int i = 2; i <= N * 2 - 1; 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;
}

void work() {
	LL n; cin >> n;
	ff();
	cout << f[n * 2] * quick_mi(2, mod - 2, mod) % mod << endl;
}

int main() {
	BUFF;
	LL T; cin >> T;
	while (T--)
		work();
	return 0;
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/289455.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号