【知识解析】
卡特兰数(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种等价的递推式:
其中,组合计算公式为:
【算法代码】
#include <stdio.h>
#include <stdlib.h>
const int maxn=10001;
int main(){
long long c[maxn],ans,n;
scanf("%d",&n);
c[0]=1;
c[1]=1;
int i,j;
for(i=2;i<=n;i++){
for(j=0;j<=i-1;j++){
c[i]+=c[j]*c[i-j-1];
}
}
int k;
for(k=0;k<=n;k++){
printf("%d ",c[k]);
}
return 0;
}
/*
in:6
out:1 1 2 5 14 42 132
*/
【参考文献】
https://www.luogu.com.cn/problem/P1044
https://www.luogu.com.cn/problem/solution/P1044
https://blog.csdn.net/SunnyLi1106/article/details/128534981
https://leetcode.cn/circle/article/lWYCzv/