加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

HDU 1023 Train Problem II 卡特兰数 大数的乘法除法

发布时间:2020-12-14 03:31:53 所属栏目:大数据 来源:网络整理
导读:Train Problem II Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5622????Accepted Submission(s): 3040 Problem Description As we all know the Train Problem I,the boss of the Ignatius

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5622????Accepted Submission(s): 3040

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

/*
1023 Train Problem II
不知道思路 看别人的都说是卡特兰数
 1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700,1767263190,6564120420,24466267020,91482563640,343059613650,1289904147324,4861946401452...
F(n)=F(n-1)*(4n-2)/(n+1)
*/

#include<iostream>
using namespace std;
int a[101][101]={0};//a[i]表示的是第i个数 
                    //因为是大数 [j]表示的是这个数的若干位 
int main(){
    int b[101],i,j,n,k,z; 

        a[1][0]=1;
        b[1]=1;
        k=1;//长度 
        for(i=2;i<101;i++)
        {
            for(j=0;j<k;j++)
                a[i][j]=a[i-1][j]*(4*i-2);//乘法大数 每位乘以
            z=0;//进位 
            for(j=0;j<k;j++)
            {
                a[i][j]+=z;
                z=a[i][j]/10;
                a[i][j]%=10;
            } 
            while(z)//仍有进位 
            {
                a[i][k++]=z%10;
                z/=10;
            }
            
            //大数除法 模拟除法 从高到低
            z=0; 
            for(j=k-1;j>=0;j--)
            {
                a[i][j]+=z*10;//上一位剩的
                z=a[i][j]%(i+1);
                a[i][j]/=(i+1);
            } 
            while(!a[i][k-1])//去除前面的0 
                k--;
            b[i]=k; //保存n的大数的长度 
        }
        
        while(cin>>n)
        {
            for(i=b[n]-1;i>=0;i--)
                cout<<a[n][i];
            cout<<endl;
        }     
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读