'commit'
This commit is contained in:
40
TangDou/LuoGuBook/P1044_3.cpp
Normal file
40
TangDou/LuoGuBook/P1044_3.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user