题解
非交叉匹配
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9+7;
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll inv(ll x) {
return qpow(x, mod - 2); // 使用费马小定理计算逆元
}
ll C(ll n, ll m) {
if (m > n) return 0;
ll res = 1;
for (ll i = 1; i <= m; i++) {
res = res * (n - i + 1) % mod;
res = res * inv(i) % mod;
}
return res;
}
void solve() {
ll n;
cin >> n;
if(n & 1) {
cout << 0 << endl;
return;
}
ll ans = C(n, n/2) * inv(n/2 + 1) % mod; // 计算 Catalan 数
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll TT = 1;
//cin >> TT;
while (TT--) solve();
return 0;
}
标签:return,P1375,res,ll,long,小猫,mod
From: https://www.cnblogs.com/pure4knowledge/p/18330962