(组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)

package com.njupt.acm;



import java.math.BigInteger;

import java.util.Scanner;







public class POJ_2084 {

	

	public static void main(String[] args) {

		BigInteger catalan[] = new BigInteger[102];

		catalan[1] = new BigInteger("1");

		

		BigInteger one = new BigInteger("1");

		BigInteger two = new BigInteger("2");

		BigInteger four = new BigInteger("4");

		

		int i;

		for(i = 1 ; i <= 100 ; ++i){

			

			catalan[i+1] = catalan[i].multiply(four.multiply(new BigInteger(i + "")).subtract(two)).divide(new BigInteger(i + "" ).add(one));

			

		}

		

		Scanner scanner = new Scanner(System.in);

		int n ;

		

		while(true){

			n = scanner.nextInt();

			if(n < 0){

				break;

			}

			

			System.out.println(catalan[n + 1]);

		}

		

	}

}


你可能感兴趣的:(Connection)