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?
Input
Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.
Output
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.
2
3
-1
2
5
题意:有2n个人围成一圈,两两相连,连线不能交叉,问有多少种方式(n<100)。
好理解,于是我一开始尝试一个个的画出来,然后画到n=5的时候就发现太多了,而且完全没有规律。之后就去看别人写的博客,发现这属于卡特兰数(原谅我这个渣渣第一次遇到这种题)。
卡特兰数:f(n)=f(0)f(n-1)+f(1)f(n-2)+f(2)f(n-3),,,,,f(n-1)f(0)。
递推:h(n)=h(n-1)(4n-2)/h(n-1)。
经典题:一张票5元,n个人有5元,n个人有10元,开始售票员没有钱,每人买一张票,求不发生售票员找不开钱的情况有多少种?
自己的理解:5元为a,10元为b,必须a和b连,求有多少种方法去连接a和b。(本题中相连的两个点中间剩余的点的个数不能为单个,因为这样就相交了)
然后我用电脑演算了一遍发现用long long来存结果,n只能到33!!!
之后就去学习大数(好难,还没学会。。。。)