Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6418 Accepted Submission(s):
3494
import java.io.*; import java.util.*; import java.math.*; public class Main { public static BigInteger fac(BigInteger n){ BigInteger a=new BigInteger("1"); BigInteger zero=new BigInteger("0"); if(n.equals(a)||n.equals(zero)) return a; return n.multiply(fac(n.subtract(a))); } public static BigInteger C(BigInteger n,BigInteger k){ return fac(n).divide(fac(k).multiply(fac(n.subtract(k)))); } public static BigInteger Catlan(BigInteger n){ BigInteger a=new BigInteger("1"); return C(n.add(n),n).divide(n.add(a)); } public static void main(String[] args){ Scanner in=new Scanner(System.in); BigInteger n; BigInteger two=new BigInteger("2"); while(in.hasNext()){ n=in.nextBigInteger(); System.out.println(Catlan(n).toString()); } } }
原文:http://www.cnblogs.com/--560/p/4362514.html