卡特兰数 ← 递推法

【知识解析】
卡特兰数(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]=\left\{\begin{matrix} 1,(n=0,1)\\ {\color{Red} h[0]*h[n-1]+h[1]*h[n-2]+\cdots h[n-1]*h[0]} ,(n\geqslant 2) \end{matrix}\right.
h[n]={\color{Red} h[n-1]*(4n-2)/(n+1)},(n\geqslant 2)
h[n]=\binom{2n}{n}-\binom{2n}{n-1},(n=0,1,2,\cdots )
h[n]={\color{Red} \binom{2n}{n}/(n+1)},(n=0,1,2,\cdots )
其中,组合计算公式为: C_{n}^{m}=\binom{n}{m}=\frac{n!}{m!(n-m)!} 

【算法代码】

#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/




 

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值