首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-10-10 
(组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)package com.njupt.acmimport java.

(组合数学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]);}}}

热点排行