HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
来源:互联网 发布:淘宝招聘手模特 编辑:程序博客网 时间:2024/05/22 03:36
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
12310
Sample Output
12516796
/*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;}
0 0
- HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
- HDU.1023 Train Problem II【大数除法、卡特兰数】--用于求出栈的n种方式(3.15)
- HDU Train Problem II (卡特兰数+大数)
- HDOJ 1023 Train Problem II(卡特兰数+大数乘除法)
- HDU 1023 -- Train Problem II (卡特兰 Java大数)
- HDU 1023 Train Problem II 卡特兰数 及完全大数模板
- hdu 1023 Train Problem II (卡特兰数)
- Train Problem II hdu 1023 卡特兰数 (模板)
- hdu 1023 Train Problem II (卡特兰数)
- HDU 1023 Train Problem II(卡特兰数)
- hdu 1023 Train Problem II dp/卡特兰数
- hdu 1023 Train Problem II(卡特兰数)
- hdu 1023 Train Problem II(java+卡特兰数)
- HDU 1023 Train Problem II(卡特兰数)
- hdu 1023 Train Problem II (卡特兰数)
- HDU-1023 Train Problem II(卡特兰数)
- hdu 1023 Train Problem II 卡特兰数+java
- hdu 1023 Train Problem II【卡特兰数】
- 多线程编程3 - NSOperationQueue
- 多线程编程2 - NSOperation
- 前:前面加上某些文本 20140625
- 人脸识别数据库
- 多线程编程1 - NSThread
- HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
- shutdown函数解析
- Unix/Linux环境C编程入门教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
- HDU 2674 N!Again 大整数N!取余数
- Android去掉UI的TitleBar
- GMT-8 GMT+8 GMT CST及系统时区查看、修改
- 利用DHT网络原理制作bt采集蜘蛛
- HDU 1002 A + B Problem II 大数相加
- Android 监控程序安装和删除的实现