卡特兰数总结

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5906    Accepted Submission(s): 3209


Problem Description
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.
 

Input
The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.
 

Output
For each test case, you should output how many ways that all the trains can get out of the railway.
 

Sample Input
  
  
1 2 3 10
 

Sample Output
  
  
1 2 5 16796
Hint
The result will be very large, so you may not process it by 32-bit integers.
 

Author
Ignatius.L
解题思路:相当于对一个栈进行n次操作,问有多少种不同的顺序,卡特兰数

小兔的棋盘

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6447    Accepted Submission(s): 3500


Problem Description
小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点),这样的路径数有多少?小兔想了很长时间都没想出来,现在想请你帮助小兔解决这个问题,对于你来说应该不难吧!
 

Input
每次输入一个数n(1<=n<=35),当n等于-1时结束输入。
 

Output
对于每个输入数据输出路径数,具体格式看Sample。
 

Sample Input
   
   
1 3 12 -1
 

Sample Output
   
   
1 1 2 2 3 10 3 12 416024
 

Author
Rabbit
 

Source
 
解题思路:把向右走一格看做1,向上走一格看做0,即问一个序列0的个数不超过1的个数的情况有多少种,卡特兰数

Game of Connections

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3190    Accepted Submission(s): 1822


Problem Description
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.
 

Sample Input
   
   
2 3 -1
 

Sample Output
   
   
2 5
 

Source
 
百度百科关于卡特兰数的介绍
http://baike.baidu.com/view/2499752.htm?fr=aladdin

卡特兰数公式 h(n)=h(n-1)*(4*n-2)/(n+1);h(0)=1;h(1)=1;

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值