裸卡兰特数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130
卡兰特数:令h(1)=1,h(0)=1,catalan数满足递归式: //h(n)=(4*n-2)/(n+1)*h(n-1);
JAVA代码
import java.math.BigInteger; import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); BigInteger[] arr = new BigInteger[1100]; arr[0] = BigInteger.ONE; arr[1] = BigInteger.ONE; BigInteger four = BigInteger.valueOf(4); BigInteger two = BigInteger.valueOf(2); BigInteger one = BigInteger.valueOf(1); for(int i=2;i<1001;i++){ arr[i] = arr[i-1].multiply(four.multiply(BigInteger.valueOf(i)).subtract(two)).divide(BigInteger.valueOf(i).add(one)); } int pos; while(in.hasNext()){ pos = in.nextInt(); System.out.println(arr[pos]); } } }