标签:
题目大意
给定节点数 , 求通过这么多个节点能得到的二叉树的组成方式
用卡特兰数解决
f[n] = (4*n-2) * f[n-1] / (n+1);
递归不断解决
1 /** 2 * @(#)Main.java 3 * 4 * 5 * @author 6 * @version 1.00 2014/12/29 7 */ 8 9 import java.util.Scanner; 10 import java.math.*; 11 12 public class Main { 13 14 15 public static void main(String [] args){ 16 int n; 17 Scanner input = new Scanner(System.in); 18 19 while(input.hasNext()){ 20 n = input.nextInt(); 21 BigInteger cur = BigInteger.valueOf(1); 22 for(int i = 2 ; i<=n ; i++){ 23 int t1 = 4*i - 2; 24 int t2 = i+1; 25 BigInteger tmp1 = BigInteger.valueOf(t1); 26 cur = cur.multiply(tmp1); 27 BigInteger tmp2 = BigInteger.valueOf(t2); 28 cur = cur.divide(tmp2); 29 } 30 System.out.println(cur); 31 } 32 } 33 34 35 }
标签:
原文地址:http://www.cnblogs.com/CSU3901130321/p/4190892.html