hdu-2067 卡特兰数

小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(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


典型的卡特兰数,https://baike.baidu.com/item/%E5%8D%A1%E7%89%B9%E5%85%B0%E6%95%B0/6125746?fr=aladdin
 1 #include<cstdlib>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<string>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<cmath>
 8 #include<set>
 9 #include<sstream>
10 #include<iterator>
11 using namespace std;
12 typedef long long ll;
13 ll c[36];
14 void Catalan()
15 {
16     memset(c, 0, sizeof(c));
17     c[0] = c[1] = 1;
18     for (int i = 2; i <= 35; i++)
19         for (int j = 0; j<i; j++)
20         {
21             c[i] += c[j] * c[i - j - 1];
22         }
23 }
24 int main()
25 {
26     ll n;
27     ll t = 1;
28     Catalan();
29     while (scanf("%lld", &n) != EOF && n != -1)
30     {
31         printf("%lld %lld %lld
",t++, n, c[n]*2);
32     }
33     return 0;
34 }
原文地址:https://www.cnblogs.com/xujunming/p/7774764.html