You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
761 B

2 years ago
#include <bits/stdc++.h>
// 超棒的讲解
// https://www.bilibili.com/video/BV1nE411A7ST?from=search&seid=2618099886973795159
using namespace std;
/**
n=1 1
n=2 2
n=3 5
n=4 14
n=5 42
n=6 132
n=7 429
n=8 1430
n=9 4862
n=10 16796
n=11 58786
n=12 208012
n=13 742900
n=14 2674440
n=15 9694845
n=16 35357670
n=17 129644790
n=18 477638700
*/
int catalan(int n) {
if (n == 0 || n == 1) return 1;
int res = 0;
for (int i = 1; i <= n; i++) res += catalan(i - 1) * catalan(n - i);
return res;
}
int main() {
int n;
cin >> n;
cout << catalan(n) << endl;
return 0;
}