Game of Connections
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another.
And, no two segments are allowed to intersect.
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
给你2n个数,让这些数按照顺序围成一个圈,任意两个数可以连接,但是每个数只能连接一次,且连线不能交叉,问你一共有多少种方式。
卡特兰数
但是要求是高精度,于是Java了。
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner cinScanner=new Scanner(System.in);
int times,j,l;
BigInteger []k=new BigInteger[107];
k[0]=BigInteger.valueOf(1);
for(j=1;j<=100;j++)
{
k[j]=BigInteger.valueOf(0);
for (l=0;l<=j-1;l++)
{
k[j]=k[j].add(k[l].multiply(k[j-1-l]));
}
}
while (cinScanner.hasNext())
{
times=cinScanner.nextInt();
if(times!=-1)
System.out.println(k[times]);
else {
break;
}
}
}
}