zoukankan      html  css  js  c++  java
  • 卡特兰数

    卡塔兰数组合数学中一个常在各种计数问题中出现的数列。仍存有疑惑,之后再解释;

    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.
    #include <algorithm>
    #include<iostream>
    #include <cstring>
    #include<stdio.h>
    #define maxn 1000
    using namespace std;
    int cata[105][maxn];
    
    void op()
    {
        cata[1][0] = 1;
        cata[1][1] = 1;
        cata[2][1] = 2;
        cata[2][0] = 1;
        int len = 1, yu;
        int i, j;
        for (i = 3; i<101; i++)
        {
            yu = 0;
            for (j = 1; j <= len; j++)
            {
                int it = cata[i - 1][j] * (4 * i - 2) + yu;
                yu = it / 10;
                cata[i][j] = it % 10;
            }
            while (yu)
            {
                cata[i][++len] = yu % 10;
                yu /= 10;//归零;
            }
    
            for (j = len; j >= 1; j--)
            {
                int it = cata[i][j] + yu * 10;
                cata[i][j] = it / (i + 1);
                yu = it % (i + 1);
            }
            while (cata[i][len]==0)
            {
                len--;
            }
            cata[i][0] = len;
        }
    }
    
    int main()
    {
        op();
        int n;
        while (scanf("%d", &n) != EOF)
        {
            for (int i = cata[n][0]; i>0; i--)
                printf("%d", cata[n][i]);
            printf("
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    objectMediator
    vi
    string regex
    ar
    widget class in class
    Makefile 语法分析 第三部分
    在Makefile中的 ".PHONY "是做什么的?
    】openssl移植Android使用及其相关经验分享
    精品Android源码推荐,看了绝不后悔
    Makefile 语法分析 第三部分
  • 原文地址:https://www.cnblogs.com/7750-13/p/7278451.html
Copyright © 2011-2022 走看看