【知识解析】
● 卡特兰数(Catalan number)是组合数学中一个常出现在各种计数问题中的数列。
若从第0项开始,则卡特兰数列 h[n] 为:1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, …
● 卡特兰数列 h[n] 有如下4种等价的递推式:
h[n]=h[0]*h[n−1]+h[1]*h[n−2]+...+h[n−1]*h[0], (n≥2, h[0]=h[1]=1)
h[n]=h[n−1]*(4*n−2)/(n+1), (n≥2)
h[n]=C(2n,n)−C(2n,n−1), (n=0,1,2,...)
h[n]=C(2n,n)/(n+1), (n=0,1,2,...)
其中,组合计算公式为:
【算法代码】
#include <bits/stdc++.h>
using namespace std;
const int maxn=25;
long long c[maxn];
int n;
int main() {
cin>>n;
c[0]=1,c[1]=1;
for(int i=2; i<=n; i++)
for(int j=0; j<=i-1; j++)
c[i]+=c[j]*c[i-j-1];
for(int i=0; i<=n; i++) {
cout<<c[i]<<" ";
}
return 0;
}
/*
in:
20
out:
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 35357670 129644790 477638700 1767263190 6564120420
*/
【参考文献】
https://blog.youkuaiyun.com/hnjzsyjyj/article/details/145830268
https://www.luogu.com.cn/problem/P1044
https://www.luogu.com.cn/problem/solution/P1044
https://blog.youkuaiyun.com/SunnyLi1106/article/details/128534981
https://leetcode.cn/circle/article/lWYCzv/