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;
    }
     
  • 相关阅读:
    flexbox弹性盒子布局
    LAMP环境 源码包安装
    用条件注释判断浏览器版本,解决兼容问题
    事件冒泡和事件捕获
    为js和css文件自动添加版本号
    uEditor独立图片上传
    修改netbeans模版头部的说明
    thinkphp多表关联并且分页
    thinkphp 独立分组配置
    荣耀路由HiLink一键组网如何实现?
  • 原文地址:https://www.cnblogs.com/7750-13/p/7278451.html
Copyright © 2011-2022 走看看