首页 > 代码库 > A - Train Problem II ( 火车和卡特兰数 )
A - Train Problem II ( 火车和卡特兰数 )
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.
InputThe 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.
OutputFor 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.
1 #include <iostream>
2 #include <string.h>
3 using namespace std;
4
5 const int MAX = 305;
6 int a[MAX][MAX];
7
8
9 void chengf(int x,int i)
10 {
11 int temp = 0;;
12 for(int j = 300;j >=0;j--)
13 {
14 temp = a[i-1][j]*x + temp;
15 a[i][j] = temp % 10;
16 temp = temp / 10;
17
18 }
19 }
20
21 void chuf(int x,int i)
22 {
23 int temp = 0;
24 for(int j = 0;j <=300;j++)
25 {
26 temp = temp *10 + a[i][j];
27 a[i][j] = temp / x;
28 temp = temp %x;
29 }
30 }
31
32 void DP()
33 {
34 memset(a,0,sizeof(a));
35 a[1][300] = 1;
36 for(int i = 2;i <= 100;i++)
37 {
38 int temp = 4*i - 2;
39 chengf(temp,i);
40 temp = i + 1;
41 chuf(temp,i);
42 }
43 }
44
45 int main()
46 {
47 int n;
48 DP();
49 while(cin>>n)
50 {
51 int temp = 0;
52 for(int i = 0;i <= 300;i++)
53 {
54 if(a[n][i]!=0)
55 {
56 temp = i;
57 break;
58 }
59 }
60 for(int i = temp;i <=300;i++)
61 cout<<a[n][i];
62 cout<<endl;
63
64 }
65
66 return 0;
67 }
A - Train Problem II ( 火车和卡特兰数 )
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。