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