hdu1134卡特兰数

简单卡特兰数题,卡特兰序列:1,1,2,5,14,42,132,429,1430·············

递推式f(n)=f(n-1)*(4n-2)/ (n+1) 

import java.math.BigInteger;
import java.util.Scanner;

public class hdu1134 {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        BigInteger aa[] = new BigInteger[101];
        aa[1] = BigInteger.ONE;
        for (int i = 2; i < aa.length; i++) {
            BigInteger bi = new BigInteger(4*i-2+"");//这里的val是十进制数字
            BigInteger bii = new BigInteger(i+1+"");
            aa[i] = aa[i-1].multiply(bi).divide(bii);
        }
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int x = sc.nextInt();
            if (x==-1) {
                break;
            }
            System.out.println(aa[x]);
        }
        sc.close();
    }
}

 

posted @ 2024-05-15 23:49  XiaohuangTX  阅读(1)  评论(0编辑  收藏  举报