码迷,mamicode.com
首页 > 其他好文 > 详细

【codevs】3112 二叉树计数

时间:2014-10-02 23:28:43      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   for   

时间限制: 1 s
空间限制: 128000 KB
题目等级 : 黄金 Gold
 
 
 

题目描述 Description

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

输入描述 Input Description

读入一个正整数n

输出描述 Output Description

输出一个正整数表示答案

样例输入 Sample Input

6

样例输出 Sample Output

132

数据范围及提示 Data Size & Hint

1<=n<=20

分析

catalan数

f[2]=f[3]=1;

f[n+1]=(4n-6)/n*f[n];

bubuko.com,布布扣
 1 # include<cstdio>
 2 # include<cstring>
 3 # include<iostream>
 4 # include<algorithm>
 5 using namespace std;
 6 typedef unsigned long long LL;
 7 const int maxn=25;
 8 LL f[maxn];
 9 int main(){
10     f[2]=f[3]=1;
11     for(int i=3;i<=maxn;i++)
12     f[i+1]=(4*i-6)*f[i]/i;
13     int n;cin>>n;
14     cout<<f[n+2];
15     return 0;
16 }
View Code

 

【codevs】3112 二叉树计数

标签:des   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/zoniony/p/4004465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!