Description
Another common social inability is known as ACM (abnormally compulsive meditation). This psychological disorder is somewhat common among programmers. It can be described as the temporary (although frequent) loss of the faculty in speech when the whole power of the brain I s applied to something extremely interesting or challenging.
Juan is a very gifted programmer, and have a severe case of ACM (he even participated in an ACM World championship a few MO Nths ago). Lately, his loved ones is worried about him, because he had found a new exciting problem to exercise his intellectual POW ERS, and he have been speechless for several weeks now. The problem is the determination of the number of different labeled binary trees so can be built using exactlyn Different elements.
For example, given one element A, just one binary tree can is formed (usingA as the root of the tree). With-elements, A and B, four different binary trees can is created, as shown in the figure.
If you is able to provide a solution for this problem, Juan would be able to talk again, and his friends and family would b e forever grateful.
InputThe input would consist of several input cases, one per line. Each input case is specified by the number
N(
1≤n≤300) of different elements that must is used to form the trees. A number0Would mark the end of input and is not to be processed.OutputFor each input case print the number of binary trees that can be built using the
NElements, followed by a newline character.Sample Input
1210250
Sample Output
146094932480075414671852339208296275849248768000000
Test instructions: Cattleya number
Idea: Java practiced hand
Import Java.math.biginteger;import java.util.*;import java.io.*;/** * Created by Acer on 14-8-7. */public class Main {public static void Main (string[] args) {Scanner cin = new Scanner (system.in); biginteger[] Catalan = new biginteger[301], fact = new Biginteger[601];int n;fact[0] = biginteger.one;for (int i = 1; I &l T;= 600; i++) Fact[i] = fact[i-1].multiply (biginteger.valueof (i)); for (int i = 0; I <=; i++) Catalan[i] = Fact[i*2].divide (FAC T[i+1]). Divide (Fact[i]), while ((n = cin.nextint ())! = 0) System.out.println (catalan[n].multiply (fact[n)));}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
UVA-10007 Count the Trees