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;
    }
     
  • 相关阅读:
    SourceTree
    记录:解决标签在选中状态下,鼠标进入(hover)后变色的问题
    在angular中超过字数后以...展示
    小程序下拉刷新步骤——完成
    eclipse配置文件乱码
    jQuery的deferred对象
    营销策划书(2007)
    前端IT攻城狮--网址搜藏(-- 欢迎留言补充 --)
    prop和attr的区别
    HTML速写
  • 原文地址:https://www.cnblogs.com/7750-13/p/7278451.html
Copyright © 2011-2022 走看看