/*
* 题目:C.Catalan Square
* 链接:http://acm.bnu.edu.cn/v3/problem_show.php?pid=48266
* 题意:输入n,求S[n]。
* 分析:由已知得,S[n]=Catalan[n+1];Catalan[n]=C(2*n,n)/(n+1),所以S[n]=C(2*(n+1),(n+1))/((n+1)+1)。
* */
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.*;
public class classMain {
final static int maxn=5005;
static BigInteger[] C= new BigInteger[maxn] ;
public static void main(String[] args) {
Scanner cin = new Scanner (new BufferedInputStream(System.in));
int n,k;
while(cin.hasNextInt()){
n=cin.nextInt();
n++;
C[0]=BigInteger.ONE;
for(k=0;k+1<=n;k++){//求C(2*(n+1),(n+1))
BigInteger K=BigInteger.valueOf(k);
C[k+1]=(C[k].multiply(BigInteger.valueOf(2*n-k))).divide(BigInteger.valueOf(k+1));
}
System.out.println(C[n].divide(BigInteger.valueOf(n+1)));//答案S[n]=C(2*(n+1),(n+1))/((n+1)+1)
}
}
}
(java大数)NCPC2015.4.16,C.Catalan Square
最新推荐文章于 2022-08-10 19:40:04 发布