HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
2014-06-25 19:18
369 查看
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 -1;i>=0;i--) cout<<a [i]; cout<<endl; } return 0; }
相关文章推荐
- 杭电ACM OJ 1023 Train Problem II 卡特兰数 + 大数乘法 轻松解决出栈情况计数
- hdu 1023 Train Problem II (卡特兰数)
- hdu 1023 Train Problem II (卡特兰数)
- HDU_1023_Train Problem II_卡特兰数
- hdu1023 Train Problem II 卡特兰数,JAVA大数类
- HDU 1023 Train Problem II (卡特兰数)
- hdu 1023 Train Problem II(catalan 大数)uva 10303 uva 991
- 数学 ( 卡特兰数 大数打表模板 )——Train Problem II ( HDU )
- hdu 1023 ——Train Problem II(卡特兰数+高精度+java)
- hdu 1023 Train Problem II (卡特兰数)
- hdu 1023 Train Problem II_出栈方法数_卡特兰数
- HDU Train Problem II (卡特兰数+大数)
- HDU 1023 Train Problem II (打表求解卡特兰数)
- HDU 1023 Train Problem II (卡特兰数,经典)
- HDU 1023 Train Problem II 卡特兰数 高精度
- HDU 1023 Train Problem II 大数打表Catalan数
- hdu 1023 Train Problem II(卡特兰数的应用)出栈序列的统计
- HDU.1023 Train Problem II【大数除法、卡特兰数】--用于求出栈的n种方式(3.15)
- HDU 1023 Train Problem II(Catalan + 大数)
- HDU 1023 Train Problem II (卡特兰数)未解决未解决未解决未解决