HDU 1023 Train Problem II

8 篇文章 0 订阅
7 篇文章 0 订阅

Train Problem II
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
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 several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.

Output
For 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.
[/hint]


完全没看懂题目 但是知道是卡特兰数…..

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
#include<bitset>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007

struct BigNum{
    deque<int>num;
    //构造函数
    BigNum(){
        num.push_back(0);
    }
    BigNum(int x){
        if(!x)
            num.push_back(0);
        while(x){
            num.push_front(x%10);
            x/=10;
        }
    }
    //重载运算符
    BigNum operator+(const BigNum&x){//大数加法
        BigNum res;
        const deque<int>&a=num,&b=x.num;
        deque<int>&c=res.num;
        int alen=a.size(),blen=b.size();
        c.resize(max(alen,blen));
        for(int i=1,len=c.size();i<=c.size();++i){
            if(alen>=i)
                c[len-i]+=a[alen-i];
            if(blen>=i)
                c[len-i]+=b[blen-i];
        }
        for(int i=c.size()-1;i>0;--i){
            c[i-1]+=c[i]/10;
            c[i]%=10;
        }
        if(c[0]>9){
            c[0]-=10;
            c.push_front(1);
        }
        return res;
    }
    BigNum operator*(const BigNum&x){//大数乘法
        int zeros=0;
        BigNum res,t;
        const deque<int>&a=this->num,&b=x.num;
        deque<int>&tem=t.num;
        for(int i=b.size()-1;i>=0;--i){
            tem.clear();
            for(int j=0;j<a.size();++j)
                tem.push_back(a[j]*b[i]);
            for(int j=0;j<zeros;++j)
                tem.push_back(0);
            for(int j=tem.size()-1;j>0;--j){
                tem[j-1]+=tem[j]/10;
                tem[j]%=10;
            }
            if(tem[0]>9){
                tem.push_front(tem[0]/10);
                tem[1]%=10;
            }
            res=res+t;
            ++zeros;
        }
        while(res.num.size()>1&&res.num[0]==0)
            res.num.pop_front();
        return res;
    }
};

ostream&operator<<(ostream&out,BigNum&x){
    deque<int>&a=x.num;
    for(int i=0;i<a.size();++i)
        cout<<a[i];
    return out;
}

BigNum c[201];

void init(){
    c[0]=c[1]=BigNum(1);
    for(int i=2;i<=200;++i)
        for(int j=0;j<=i-2;j+=2)
            c[i]=c[i]+c[j]*c[i-2-j];
}

int main()
{
    //freopen("/home/lu/文档/r.txt","r",stdin);
    //freopen("/home/lu/文档/w.txt","w",stdout);
    int n;
    init();
    BigNum res;
    while(cin>>n&&n){
        cout<<c[2*n]<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值