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 of speech when the whole power of the brain is applied to something extremely interesting or challenging.
Juan is a very gifted programmer, and has a severe case of ACM (he even participant ipated in an ACM World Championship a few months ago ). lately, his loved ones are worried about him, because he has found a new exciting problem to exercise his intellectual powers, and he has been speechless for several weeks now. the problem is the determination of the number of different labeled Binary Trees that can be built using exactlyNDifferent elements.
For example, given one elementA, Just one binary tree can be formed (usingAAs the root of the tree). With two elements,AAndB, Four different binary trees can be created, as shown in the figure.
If you are able to provide a solution for this problem, Juan will be able to talk again, and his friends and family will be forever grateful.
Input the input will consist of several input cases, one per line. Each input case will be specified by the number
N(
1 ≤ n ≤300) Of different elements that must be used to form the trees. A number 0Will mark the end of input and is not to be processed. output for each input case print the number of Binary Trees that can be built using
NElements, followed by a newline character. sample input
1210250
Sample output
146094932480075414671852339208296275849248768000000
Question: catlands
Idea: Java trainer
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 <= 600; i++)fact[i] = fact[i-1].multiply(BigInteger.valueOf(i));for (int i = 0; i <= 300; i++)catalan[i] = fact[i*2].divide(fact[i+1]).divide(fact[i]);while ((n = cin.nextInt()) != 0)System.out.println(catalan[n].multiply(fact[n]));}}