UVA_10303
Set f [I] to indicate the number of binary search trees when there are a total of I elements, then we take 1-n as the root, then we will get f [n] = f [0] * f [n-1] + f [1] * f [N-2] +... + F [n-1] * f [0]. If we perform a ing of f [n] = p [n + 1, f [n] = p [n + 1] = p [1] * p [n] + p [2] * p [n-1] +... + P [n] * p [1], so that the right side becomes the catlan number, therefore, even if we find the relationship between f [n] And catlan number's generic p [n], that is, f [n] = p [n + 1].
Because p [1] = 1, p [2] = 1, p [n] = (4n-6)/n * p [n-1], f [n] = (4n-2)/(n + 1) * f [n-1]
Import java. math. BigInteger;
Import java. util. collections;
Public class Main {
Public static void main (String [] args ){
Cin = new partition (System. in );
BigInteger [] f = new BigInteger [1010];
F [1] = new BigInteger ("1 ");
For (int I = 2; I <= 1000; I ++)
F [I] = f [I-1]. multiply (BigInteger. valueOf (4 * I-2). divide (BigInteger. valueOf (I + 1 ));
While (cin. hasNext ())
{
Int n = cin. nextInt ();
System. out. println (f [n]);
}
}
}