卡特兰数总结

来源:互联网 发布:淘宝一键删除宝贝 编辑:程序博客网 时间:2024/04/28 18:54

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
12310
 

Sample Output
12516796
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
1312-1
 

Sample Output
1 1 22 3 103 12 416024
 

Author
Rabbit
 

Source
RPG专场练习赛
 
解题思路:把向右走一格看做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
23-1
 

Sample Output
25
 

Source
Asia 2004, Shanghai (Mainland China), Preliminary
 
百度百科关于卡特兰数的介绍
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;

 
0 0
原创粉丝点击