渣渣补题——学习卡特兰数(别看了,没代码)

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!!!
之后就去学习大数(好难,还没学会。。。。)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值