二叉树计数(codevs 3112)

题目描述 Description

一个有n个结点的二叉树总共有多少种形态

输入描述 Input Description

读入一个正整数n

输出描述 Output Description

输出一个正整数表示答案

样例输入 Sample Input

6

样例输出 Sample Output

132

数据范围及提示 Data Size & Hint

1<=n<=20

/*
  复习一下卡特兰数,以备考试考上模板(虽然可能性不大)
  递推式:h[1]=1,h[i]=(4*i-2)*h[i-1]/(n+1) 
  数列模式:1 1 2 5 14 42 132 429 …… 
*/
#include<cstdio>
#include<iostream> 
#define lon long long
using namespace std;
lon h[25];int n;
int main(){
    scanf("%d",&n);
    h[1]=1;
    for(int i=2;i<=n;i++){
        h[i]=(lon)(4*i-2)*h[i-1]/(lon)(i+1);
    }
    cout<<h[n];
    return 0;
}
原文地址:https://www.cnblogs.com/harden/p/6057601.html