Organize Your Train part II(hash)】的更多相关文章

http://poj.org/problem?id=3007 第一次用STL做的,TLE了,自己构造字符串哈希函数才可以.. TLE代码: #include <cstdio> #include <algorithm> #include <iostream> #include <string> #include <map> using namespace std; int main() { int n; scanf("%d",&…
Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7561   Accepted: 2194 Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The…
题意: 如上图所示,将一个字符串进行分割,反转等操作后不同字符串的个数: 例如字符串abba:可以按三种比例分割:1:3:2:2:3:1 部分反转可以得到如下所有的字符串: 去掉重复可以得到六个不同的字符串,输出6: 解题思路: 此题用反转函数reverse比较方便,然后就和模拟差不多,要列出所有情况,把不同的字符串保存在一个字符数组中,每次得到一个字符串都和该字符数字中的每一个比较,如果都不相同,把它存入字符数组:. 直接看代码吧: //Organize Your Train part II…
Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6478   Accepted: 1871 Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The…
Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8787   Accepted: 2490 Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The…
http://poj.org/problem?id=3007 题意 :给你一个字符串,让你无论从什么地方分割,把这个字符串分成两部分s1和s2,然后再求出s3和s4,让你进行组合,看能出来多少种不同的形式. 思路 :记得以前的时候就听他们讨论这道题,说是用map做会超时,所以我直接就没用map....但是做这道题实在是太波折了,昨天晚上改了一晚上都不对,就是不知道哪里出了问题,今早上又改,改来改去才知道原来我new node后边缺了个括号,我很懵懂,我记得不用括号也行啊,而且我看到一个AC的代码…
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6700 Accepted: 1922 Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in…
http://poj.org/problem?id=3007 #include<cstdio> #include<algorithm> #include<cstring> #define maxn 600000 using namespace std; struct node { ]; node *next; }; int ans; node *hash[maxn]; void insert(char s[]) { int k=strlen(s); ; ; i<k…
题目:http://poj.org/problem?id=3007 题意:按照图示的改变字符串,问有多少种..字符串.. 思路:分几种排序的方法,,刚开始用map 超时(map效率不高啊..),后来搜了一下题解,用二叉排序树... 先贴AC代码: #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef struct tree { ]; struct…
Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure 1.…
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670- 令h(0)=1,h(1)=1,catalan数满足递推式:      h(n)= h(0…
题目连接 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 t…
Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7539    Accepted Submission(s): 4062 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stat…
Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10372    Accepted Submission(s): 5543 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Sta…
Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4358    Accepted Submission(s): 2391 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stati…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12035    Accepted Submission(s): 6422 Problem Description As we all know the…
Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9701    Accepted Submission(s): 5210 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stat…
问题陈述: HDOJ Problem - 1023 问题解析: 卡特兰数(Catalan)的应用 基本性质: f(n) = f(1)f(n-1) + f(2)f(n-2) + ... + f(n-2)f(2) + f(n-1)f(1); f(n) = C(2n, n) / (n+1) = C(2n-2, n-1) / n;  Cn = (4n-2)/(n+1) Cn-1 代码详解: I: C++ #include <iostream> #include <cstdio> #incl…
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…
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 te…
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…
题目链接_HDU-1023 题目 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 sever…
卡特兰数: Catalan数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) (其中n>=2) 另类递归式: h(n)=((4*n-2)/(n+1))*h(n-1); 该递推关系的解为: h(n+1)=C(2n,n)/(n+1) (n=1,2,3,...) 最典型的四类应用:(实质上却都一样,无非是递归等式的应用,就看你能不能分解问题写出递归式了) 1.括号化问题. 矩阵链乘…
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #include <bits/stdc++.h> using namespace std; ; vector<string> vect; void _mult(string num1, string num2, string &result ) { reverse(num1.begin()…
考虑第1个火车出站的时刻,从1到n都有可能,如果它是第i个出栈,那么前面有规模为i-1的子问题,后面有规模为n-i的子问题.累加.…
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n,n) / (n+1); 递推公式 C(n ) = C(n-1)*(4*n-2) / (n+1) 高精度乘以一个整数和高精度除以一个整数的知识.这样还是使用整数数组比較好计算,假设使用string那么就不太好计算了,由于整数也可能是多位的. const int MAX_N = 101; short…
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. 前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 176…
链接:传送门 题意:裸卡特兰数,但是必须用大数做 balabala:上交高精度模板题,增加一下熟悉度 /************************************************************************* > File Name: hdu1023.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年05月11日 星期四 19…
题目链接:https://cn.vjudge.net/problem/HDU-1023 题意 卡特兰数的应用之一 求一个长度为n的序列通过栈后的结果序列有几种 思路 一开始不知道什么是卡特兰数,猜测是一个递推题 注意到在序列第i个元素入栈时,前几个元素都进过栈,就是通过栈的操作 设n个元素通过栈的结果序列个数为h[n],则有: \[ h_n=h_1h_{n-1}+h_2h_{n-2}+...+h_{n-1}h_1 \] 查了以后发现这是卡特兰数的规律,有通项: \[ h_n=h_{n-1}\fr…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目大意: 一列N节的火车以严格的顺序到一个站里.问出来的时候有多少种顺序. 解题思路: 典型的求Catalan数的题目,可是结果会非常大,所以须要用大数来解决. Catalan公式为 h(n) = h(n-1) * (4*n-2) / (n + 1),h(0) = h(1) = 1. AC代码: #include<iostream> #include<algorithm> #…