hdu 1023 Train Problem II
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=1212
Train Problem II
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.
SampleInput
1
2
3
10
SampleOutput
1
2
5
16796
卡特兰数。。
$ f(n) = f(n-1)*(n*4-2)/(n-1)$
- #include<algorithm>
- #include<iostream>
- #include<cstdlib>
- #include<cstring>
- #include<cassert>
- #include<cstdio>
- #include<vector>
- #include<string>
- #include<map>
- #include<set>
- using std::cin;
- using std::max;
- using std::cout;
- using std::endl;
- using std::string;
- using std::istream;
- using std::ostream;
- #define sz(c) (int)(c).size()
- #define all(c) (c).begin(), (c).end()
- #define iter(c) decltype((c).begin())
- #define cls(arr,val) memset(arr,val,sizeof(arr))
- #define cpresent(c, e) (find(all(c), (e)) != (c).end())
- #define rep(i, j, n) for (int i = j; i < (int)(n); i++)
- #define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
- #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
- #define pb(e) push_back(e)
- #define mp(a, b) make_pair(a, b)
- struct BigN {
- typedef unsigned long long ull;
- static const int Max_N = ;
- int len, data[Max_N];
- BigN() { memset(data, , sizeof(data)), len = ; }
- BigN(const int num) {
- memset(data, , sizeof(data));
- *this = num;
- }
- BigN(const char *num) {
- memset(data, , sizeof(data));
- *this = num;
- }
- void clear() { len = , memset(data, , sizeof(data)); }
- BigN& clean(){ while (len > && !data[len - ]) len--; return *this; }
- string str() const {
- string res = "";
- for (int i = len - ; ~i; i--) res += (char)(data[i] + '');
- if (res == "") res = "";
- res.reserve();
- return res;
- }
- BigN operator = (const int num) {
- int j = , i = num;
- do data[j++] = i % ; while (i /= );
- len = j;
- return *this;
- }
- BigN operator = (const char *num) {
- len = strlen(num);
- for (int i = ; i < len; i++) data[i] = num[len - i - ] - '';
- return *this;
- }
- BigN operator + (const BigN &x) const {
- BigN res;
- int n = max(len, x.len) + ;
- for (int i = , g = ; i < n; i++) {
- int c = data[i] + x.data[i] + g;
- res.data[res.len++] = c % ;
- g = c / ;
- }
- return res.clean();
- }
- BigN operator * (const BigN &x) const {
- BigN res;
- int n = x.len;
- res.len = n + len;
- for (int i = ; i < len; i++) {
- for (int j = , g = ; j < n; j++) {
- res.data[i + j] += data[i] * x.data[j];
- }
- }
- for (int i = ; i < res.len - ; i++) {
- res.data[i + ] += res.data[i] / ;
- res.data[i] %= ;
- }
- return res.clean();
- }
- BigN operator * (const int num) const {
- BigN res;
- res.len = len + ;
- for (int i = , g = ; i < len; i++) res.data[i] *= num;
- for (int i = ; i < res.len - ; i++) {
- res.data[i + ] += res.data[i] / ;
- res.data[i] %= ;
- }
- return res.clean();
- }
- BigN operator - (const BigN &x) const {
- assert(x <= *this);
- BigN res;
- for (int i = , g = ; i < len; i++) {
- int c = data[i] - g;
- if (i < x.len) c -= x.data[i];
- if (c >= ) g = ;
- else g = , c += ;
- res.data[res.len++] = c;
- }
- return res.clean();
- }
- BigN operator / (const BigN &x) const {
- BigN res, f = ;
- for (int i = len - ; ~i; i--) {
- f *= ;
- f.data[] = data[i];
- while (f >= x) {
- f -= x;
- res.data[i]++;
- }
- }
- res.len = len;
- return res.clean();
- }
- BigN operator % (const BigN &x) {
- BigN res = *this / x;
- res = *this - res * x;
- return res;
- }
- BigN operator += (const BigN &x) { return *this = *this + x; }
- BigN operator *= (const BigN &x) { return *this = *this * x; }
- BigN operator -= (const BigN &x) { return *this = *this - x; }
- BigN operator /= (const BigN &x) { return *this = *this / x; }
- BigN operator %= (const BigN &x) { return *this = *this % x; }
- bool operator < (const BigN &x) const {
- if (len != x.len) return len < x.len;
- for (int i = len - ; ~i; i--) {
- if (data[i] != x.data[i]) return data[i] < x.data[i];
- }
- return false;
- }
- bool operator >(const BigN &x) const { return x < *this; }
- bool operator<=(const BigN &x) const { return !(x < *this); }
- bool operator>=(const BigN &x) const { return !(*this < x); }
- bool operator!=(const BigN &x) const { return x < *this || *this < x; }
- bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
- friend istream& operator >> (istream &in, BigN &x) {
- string src;
- in >> src;
- x = src.c_str();
- return in;
- }
- friend ostream& operator << (ostream &out, const BigN &x) {
- out << x.str();
- return out;
- }
- }A[], B;
- inline void init() {
- A[] = ;
- rep(i, , ) {
- B = * i - ;
- A[i] = A[i - ] * B / (i + );
- B.clear();
- }
- }
- int main() {
- #ifdef LOCAL
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w+", stdout);
- #endif
- init();
- std::ios::sync_with_stdio(false);
- int n;
- while (cin >> n) cout << A[n] << endl;
- return ;
- }
hdu 1023 Train Problem II的更多相关文章
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
- HDU 1023 Train Problem II( 大数卡特兰 )
链接:传送门 题意:裸卡特兰数,但是必须用大数做 balabala:上交高精度模板题,增加一下熟悉度 /************************************************ ...
- 1023 Train Problem II(卡特兰数)
Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...
- HDOJ 1023 Train Problem II
考虑第1个火车出站的时刻,从1到n都有可能,如果它是第i个出栈,那么前面有规模为i-1的子问题,后面有规模为n-i的子问题.累加.
- HDOJ 1023 Train Problem II 卡特兰数
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...
- Train Problem II(卡特兰数 组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
- HDU——1023 Train Problem II
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- Flex开发自定义控件
前期准备: 点击File菜单 -> New -> MXML Component,然后弹出一个对话框. 在对话框中输入组件名,选择此组件继承的类型,如:Canvas,DataGrid,Com ...
- 慕课网-安卓工程师初养成-4-7 Java循环语句之 while
来源: http://www.imooc.com/code/1420 生活中,有些时候为了完成任务,需要重复的进行某些动作.如参加 10000 米长跑,需要绕 400 米的赛道反复的跑 25 圈.在 ...
- MSP430F149学习之路——捕获/比较模式
1.捕获模式 #include <msp430x14x.h> unsigned ,last1=; unsigned ,j=; void mian(void) { WDTCTL = WDTP ...
- 洛谷P1457 城堡 The Castle
P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...
- JS 点击按钮后弹出遮罩层,有关闭按钮
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- ios7 导航栏 手势 右划 自动返回 相关
http://www.tuicool.com/articles/vMfAVv 纪录一下,
- 二模08day1解题报告
T1.高中运动会(match) N个数的最大公约数. gcd不解释. T2.智力游戏 火柴棒等式形如a+b=c,现在给出啊a,b,c求使等式成立的最小的移动次数. 火柴棒表示数字不用解释了吧,在此提醒 ...
- Oracle笔记 九、PL/SQL 游标的使用
--演示隐式游标,系统自动声明,自动打开,自动使用并且自动关闭 begin update emp set sal = 1000; dbms_output.put_line('影响的行数:' || sq ...
- HTML5和CSS3的能量究竟是怎样的?
Web设计师可以使用HTML4和CSS2.1完成一些很酷的东西.我们可以在不使用陈旧的基于table布局的基础上完成文档逻辑结构并创建内容丰富的网站.我们可以在不使用内联<font>和&l ...
- pap与chap协议
1.pap:直接在网络上发送密码明文 2.chap: 网络上发送的是密码的密文;server给client发一段随机数(challenge),client利用随机数对密码进行加密,将用户名和加密后的密 ...