HDU 1023 Train Problem II(卡特兰数)
来源:互联网 发布:钣金外壳 软件 编辑:程序博客网 时间:2024/06/10 15:51
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
12516796HintThe result will be very large, so you may not process it by 32-bit integers.#include <iostream>using namespace std;int A[105][105],b[105];//A[i][j]存的是数i的卡特兰,b[i]存的是卡特兰数i的长度void catalan() //求卡特兰数{ int i, j, len, carry, temp; A[1][0] = b[1] = 1; len = 1; for(i = 2; i <= 100; i++) { for(j = 0; j < len; j++) //乘法 A[i][j] = A[i-1][j]*(4*(i-1)+2); carry = 0; for(j = 0; j < len; j++) //处理相乘结果 { temp = A[i][j] + carry; A[i][j] = temp % 10; carry = temp / 10; } while(carry) //进位处理 { A[i][len++] = carry % 10; carry /= 10; } carry = 0; for(j = len-1; j >= 0; j--) //除法 { temp = carry*10 + A[i][j]; A[i][j] = temp/(i+1); carry = temp%(i+1); } while(!A[i][len-1]) //高位零处理 len --; b[i] = len; }}int main(){ int N; catalan(); //求卡特兰数 while(cin>>N) { for(int i=b[N]-1;i>=0;i--) cout<<A[N][i]; cout<<endl; } return 0;}
0 0
- 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【卡特兰数】
- HDU-1023-Train Problem II(卡特兰数)
- HDU 1023 Train Problem II (卡特兰数)
- hdu 1023 Train Problem II 卡特兰数
- HDU 1023 Train Problem II(卡特兰数)
- HDU 1023 Train Problem II 卡特兰数 高精度
- HDU 1023 Train Problem II (卡特兰数)
- Java基础知识与C语言的对比
- 浅谈unity3d中使用MVC框架模式
- MySQL Cluster安装
- uva11137递推和DP其实有些类似
- Android- fill_parent、wrap_content和match_parent的区别
- HDU 1023 Train Problem II(卡特兰数)
- C# 排序列表(SortedList)
- 使用泛型的单链表
- I love you 转变为 I evol uoy
- Iframe 自适应高度应用
- CocoaPods进阶:本地包管理
- Java学习笔记:Arrays
- Unity中使用UGUI与ScrollView的练习
- Speech Memorization