题目
CQXYM 计算排列长度为 2n。
置换是一个数组,由以任意顺序从 1 到 n 的 n 个不同的整数组成。例如,[2,3,1,5,4] 是排列,但 [1,2,2] 不是排列(2 在数组中出现两次),[1,3,4] 也不是排列排列(n=3 但数组中有 4 个)。
只有当满足 pi<pi+1 的 i 个数不小于 n 时,才会计算排列 p(length of 2n)。例如:
排列 [1,2,3,4] 将计数,因为这样的 i 的数量 pi<pi+1 等于 3 (i=1, i=2, i=3)。
排列 [3,2,1,4] 不会计数,因为 pi<pi+1 等于 1 (i=3) 的 i 的数量。
CQXYM 想让你帮助他计算这种以 1000000007 (109+7) 为模的排列的数量。
另外,取模是求余数。例如:
7mod3=1,因为 7=3⋅2+1,
15mod4=3,因为15=4⋅3+3。
输入
输入由多个测试用例组成。
第一行包含一个整数 t(t≥1)——测试用例的数量。测试用例的描述如下。
每个测试用例只有一行包含一个整数 n(1≤n≤105)。
保证所有测试用例的n之和不超过105
题解思路
排列是对称的(2n是偶数),要么大于n n个要么小于等于n n个 并且两种的数量因为对称肯定是一样的。
所以答案就是2*n的全排列除以2
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007 ;
int main ()
{
ios::sync_with_stdio(false);
int T ;
cin >> T ;
while( T -- )
{
long long ans = 1 ;
int n ;
cin >> n ;
for (int i = 3 ; i <= 2*n ; i++ )
ans = ans * i % mod ;
cout << ans <<"\n";
}
return 0 ;
}