标签:names space long 卡特兰 题意 bit char null int
\(C_{2n}^{n} \: C_{2n}^{n - 1} \: = \: \frac{(2n)!}{n! \: n!} \: - \: \frac{(2n)!}{(n - 1)! \: (n + 1)!} \: = \: \frac{(2n)! \: (n + 1) \: - \: (2n)! \: n}{n! \: (n + 1)!} \: = \: \frac{(2n)!}{n! \: (n + 1)!} \: = \: \frac{1}{n + 1} \cdot \frac{(2n)!}{n! \: n!} \: = \: \frac{1}{n + 1} \: C_{2n}^{n}\)
https://www.luogu.com.cn/problem/P1044
题意:求卡特兰数。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const char nl = ‘\n‘;
const int N = 55;
LL c[N][N];
void init(){
for (int i = 0; i < N; ++i){
for (int j = 0; j <= i; ++j){
if (!j) c[i][j] = 1;
else c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int n;
cin >> n;
int a = 2 * n, b = n;
cout << c[a][b] / (n + 1) << nl;
return 0;
}
标签:names space long 卡特兰 题意 bit char null int
原文地址:https://www.cnblogs.com/xiaoran991/p/14407139.html