卡特兰数

卡特兰数

\(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;
}

posted @ 2021-02-16 18:25  小燃、  阅读(17)  评论(0编辑  收藏  举报