[Codevs] 3112 Binary Tree count

Source: Internet
Author: User
Time Limit: 1 s space limit: 128000 kb title level: gold Gold Title Description Description

The total number of Binary Trees with N nodes

Input description Input description

Reads a positive integer n.

Output description Output description

Output a positive integer to indicate the answer

Sample Input Sample Input

6

Sample output Sample output

132

Data range and prompt Data size & hint

1 <= n <= 20

Analysis

Catalan count

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

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

 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 Binary Tree count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.