HDU 1131 count the trees

Source: Internet
Author: User

HDU 1131 count the trees

The combination formula of Catalan numbers is Cn = C (2n, N)/(n + 1 );

The recursive formula for this number is H (n) = H (n-1) * (4 * N-2)/(n + 1)

One application of catlan:

The problem of making a binary tree for the top node.

How many different binary trees can a given n nodes constitute?

(Can constitute H (n)

But because every node is named, that is, every node is treated as different, so the number of each catlan must be multiplied by n!

The combination formula is as follows: H (n) = (2n )! /(N + 1 )! = 2n * (2n-1 )*...... * (N + 2 ).

#include 
  
    using namespace STD; # define Max 100int f [101] [100]; inline void multiply (int A [], int Max, int B) // multiplication of large numbers. Note that parameter passing {int I, S = 0; for (I = Max-1; I> = 0; I --) {S + = B * A [I]; A [I] = S % 10000; // number S/= 10000;} void Init () {memset (F [1], 0, max * sizeof (INT); F [1] [MAX-1] = 1; for (INT I = 2; I <= 100; I ++) {f [I] [MAX-1] = 1; for (Int J = I * 2; j> = I + 2; j --) Multiply (F [I], Max, j) ;}} int main () {int N, I; Init (); while (CIN> N, N) {for (I = 0; I 
   
  

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.