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 }
 
时间: 2024-08-27 12:57:19

A - Train Problem II ( 火车和卡特兰数 )的相关文章

Train Problem II HDU 1023 卡特兰数

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 se

HDOJ 1023 Train Problem II (卡塔兰数)

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 se

hdu 1023 Train Problem II 这题运用到大数相乘+大数相除+卡特兰数

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6454    Accepted Submission(s): 3514 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stat

hdoj 1023 Train Problem II 【卡特兰数】

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6928    Accepted Submission(s): 3750 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stat

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

ACM-卡特兰数之Train Problem II——hdu1023

***************************************转载请注明出处:http://blog.csdn.net/lttree*************************************** Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5589    Accept

Train Problem II 卡特兰裸题(入门题)

Train Problem II  题目大意:给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能. 解题思路:模拟栈的问题而已.  卡特兰问题. 1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main 6 { 7 static int MS=101; 8 public static void main(String[] args) 9 { 10 Sca

C - Train Problem II——(HDU 1023 Catalan 数)

传送门 Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7616    Accepted Submission(s): 4101 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train

(母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10372    Accepted Submission(s): 5543 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Sta