Ultraviolet A 10312-expression bracketing

Source: Internet
Author: User

Question: In the tree composed of n elements, it is not the number of Binary Trees.

Analysis: combination, count, and Qaran number.

The number of Binary Trees composed of n elements is the Cn-1 of the qataran number. There is a recurrence relationship as follows:


The number of all trees composed of n elements is the number sn of the catataran number. There is a recursive relationship as follows:

Catlan Data Reference: http://blog.csdn.net/mobius_strip/article/details/39229895

Chaocatran Data Reference: http://mathworld.wolfram.com/SuperCatalanNumber.html

Output S (n)-C (n-1.

Note: The information of the number of cataras is better than that of the number of sub-accounts.

#include <iostream>#include <cstdlib>using namespace std;long long C[30] = {0};long long S[30] = {0}; int main(){S[0] = S[1] = S[2] = 1;for (int i = 3 ; i < 30 ; ++ i)S[i] = (3*(2*i-3)*S[i-1]-(i-3)*S[i-2])/i;C[0] = C[1] = 1;for (int i = 2 ; i < 30 ; ++ i)for (int j = 0 ; j < i ; ++ j)C[i] += C[j]*C[i-j-1];int n;while (cin >> n)cout << S[n]-C[n-1] << endl;return 0;}

Ultraviolet A 10312-expression bracketing

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.