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) ...
随机推荐
- windows7 下的日期没有internet时间的选项卡
原因1:你在某个域里面,退出就可以了 原因2:你把windows Time的服务给禁掉或者关掉了, 步骤:运行,输入services.msc 确定,查找到windows Time开了即可
- ffmpeg视频格式转换(Java)
命令: 高品质: ffmpeg -i E:\input\a.wmv -ab 128 -acodec libmp3lame -ac 1 -ar 22050 -r 29.97 -qscale 4 -y E ...
- pycurl
http://www.cnblogs.com/lonelycatcher/archive/2012/02/09/2344005.html http://ju.outofmemory.cn/entry/ ...
- docker 换更优秀的 文件系统 比如 OverlayFS(centos7 overlay2)
内容摘自:http://www.projectatomic.io/blog/2015/06/notes-on-fedora-centos-and-docker-storage-drivers/ doc ...
- TCP/IP之大明王朝邮差
一位大神的精华之作,原创2016-05-12 刘欣 来自码农翻身! 时间: 大明王朝天启四年, 清晨. 天色刚蒙蒙亮,我就赶着装满货物的马车来到了南城门,这里是集中处理货物的地方,一队一队的马车都来到 ...
- WP8_ListBox的用法
在Windows Phone 7 Tips (5) 中曾经提到,在Windows Phone 7 中页面的布局一般分为:Panoramic.Pivot.List和Full Screen.而通常List ...
- (笔记)angular 单选选项卡
- leetcode 8
string类型转换为int类型,需要考虑不同的转换情况. “ 04” 转换结果 4: “ 4 43” 转换结果 4: “a@12 ” 转换结果 0: “12a” ...
- Android 按键式事件
1. package com.fish.helloworld; import android.app.Activity; import android.graphics.Color; import a ...
- vsftp快速配置
/etc/vsftpd/vsftpd.confanonymous_enable=YESlocal_enable=YESwrite_enable=YESlocal_umask=022dirmessage ...