• 组合数学的卡特兰数 TOJ 3551: Game of Connections


    这个就是卡特兰数的经典问题

    直接用这个公式就好了,但是这个题涉及大数的处理h(n)=h(n-1)*(4*n-2)/(n+1)

    其实见过好几次大数的处理了,有一次他存的恰好不多于30位,直接分成两部分long long 存了

    这个只涉及到大数乘小数,大数除以小数,所以比较简单些

    3551: Game of Connections 分享至QQ空间

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 5            Accepted:4

    Description

     

    This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.

    It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?

    Input

     

    Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.

    Output

     

    For each n, print in a single line the number of ways to connect the 2n numbers into pairs.

    Sample Input

     

    2
    3
    -1

    Sample Output

    2
    5

    Hint

    The result may exceed 2^64.

    #include <stdio.h>
    int a[101][66];
    int main()
    {
        a[1][0]=1;
        for(int i=2; i<101; i++)
        {
            int c=0;
            for(int j=0; j<66; j++)
            {
                a[i][j]=a[i-1][j]*(4*i-2)+c;
                c=a[i][j]/10;
                a[i][j]%=10;
            }
            c=0;
            for(int j=65; j>=0; j--)
            {
                c=c*10+a[i][j];
                a[i][j]=c/(i+1);
                c%=(i+1);
            }
        }
        int n;
        while(~scanf("%d",&n),n>0)
        {
            int t=65;
            while(a[n][t]==0)t--;
            while(t>=0)printf("%d",a[n][t--]);
            putchar(10);
        }
        return 0;
    }

     

  • 相关阅读:
    java学习多线程之创建多线程一
    java学习之线程
    ios开发系统地图知识
    Swift3.0变化分享
    最新友盟6.1.1集成遇到的坑,自定义分享界面实现(跳转控制器做分享)
    IOS开发遇到(null)与<null>轻松处理
    友盟分享实现
    iOS 判断网络连接状态的几种方法
    GCD总结
    iOS视频边下边播--缓存播放数据流
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7463881.html
Copyright © 2020-2023  润新知