摘要:我是不是真的需要学学后缀数组了,这个题我是用后缀自动机写出来的。写的比较辛苦吧,不过对后缀自动机的理解又进了一步。不废话了,题意是让你求两个字符串的最长公共子串的长度。现在贴上我的代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <queue>#include <map>using namespace std;const int max
阅读全文
摘要:这个题目是老师添加到我们学校的oj上的,估计数据是改过了的吧。题意大概是给了n个串,让你构造出来一个长度不超过k的串,使得这n个串在构造出来的这个串中出现次数最大。这也是我的ac自动机+dp第一题。虽然理解的还不是那么透,但还是做出来了,之前因为dp数组开的过小,wa了好多遍。感觉dp跟ac自动机结合在一起,dp也不显得那么难了。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio&
阅读全文
摘要:转载自:http://news.cnblogs.com/n/164019/
阅读全文
摘要:汉语提,题意清楚。当初还卡了我一个上午。哎。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <string>#include <set>using namespace std;const int maxn=26;struct node{ int cnt; node *next[maxn]; node() { cnt=0; for(
阅读全文
摘要:字典树的题是我一个月前做的了,到现在依然记得,他是我ac的第一个字典树题目。嘻嘻。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <string>#include <set>using namespace std;const int maxn=26;const int maxlen=100;char ss1[50005][maxl
阅读全文
摘要:这题的题解随处可见。仅供参考。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <string>#include <set>using namespace std;const int maxn=10;const int maxlen=11;typedef struct TrieNode{ int flg; struct TrieNo
阅读全文
摘要:类似hash的题吧,翻译文稿。字典树搞的。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <string>#include <set>using namespace std;const int maxn=26;const int maxlen=3001;string tt,sss;struct node{ bool flg; st
阅读全文
摘要:这个题是一个好题,题意比较简单,我就不赘述了。能让你对kmp的认识更近一步吧。我以前对kmp的理解仅限于动态规划或者前后缀之类的层次上。自己浅薄。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;const int maxn=1000000+5;char s[maxn];int n,next[maxn],ncas;void init(
阅读全文
摘要:这题大概是数据比较水吧,我本以为会wa或者什么的,没想到直接亮了。讨论版里面神代码多的是,但是我也想把我的代码贴出来:ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;const int maxn=100000+5;char s1[maxn],s2[maxn];int len1,len2,next[maxn];void get_nex
阅读全文
摘要:此题就是传说中的nlogn都不可过的那题吧。网上有O(n)的解法,具体的我就不说了。代码也不贴了。我也是从人家那里学过来的。
阅读全文
摘要:这个更是比较简单,就是找一个串在另一个串是否有出现,如果没有出现,输出-1,如果出现了,输出index,如果出现多次,输出最小的那个index。下面是我的代码:ac代码:View Code #include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <limits.h>#include <stdio.h>#include <math.h>#include <vector>#include
阅读全文
摘要:kmp,题意是找一个字符串既是s1串的前缀同时又是s2后缀,并且要这个字符串的长度最大。思路是把s2串当成是文本串,s1串当成是模式串,两个串KMP。具体的见代码。呵呵。ac代码:View Code #include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;const int maxn=50000+5;char s1[maxn],s2[maxn];int n,len1,l
阅读全文
摘要:kmp的题,这题比较简单。题意大概是,在一个串中找另一个串出现的次数。下面是我ac之后的代码,时间比较长了点,78ms。ac代码:View Code #include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <limits.h>#include <stdio.h>#include <math.h>#include <vector>#include <queue>#includ
阅读全文
摘要:之前发现把题目的网页复制过来显的文章不太好,以后就不这么做了。杭州回来跟死了一样,发誓我要踏踏实实一步一步来。 这个题是kmp的题,题目意思大概是对于原串中的每个前缀,找这个前缀在原串中出现过几次,对每个前缀都这么做,并用一个计数器来累加,最后要输出的就是这个结果%10007。这个题我tle了一次,主要是现在已经懒得算什么时间复杂度了,之前赛场上我队友非要n^2搞一个一百亿的数据量,我无语到吐血。。。tle代码:主要思想就是搞出来每个前缀并与原串进行KMP,时间复杂度不是很清楚,反正是挂掉了。后来自己胡乱想了一个想法,就是next数组搞出来的是前后缀问题,那么我就可以考察next数组,看对于.
阅读全文