- 4
- 0
- 约1.28千字
- 约 6页
- 2017-11-26 发布于天津
- 举报
最长重复子串问题-Read
最长重复子串问题 By 04级计算机(2)班 张治炀 030402224 问题分析 看了题目,首先想到的是,最笨的方法,也就是一个个的比较下去,感觉应该会超时,N^3的算法. 上网搜索了下,才知道repeat是经典的弱重复子串问题,最好的算法是用后缀树,不过下载了教材看后,发现天资有限,暂时无法领悟,虽然是O(nlog(n))?or?O(n)的算法,也只好放弃了. 看了下书上的KMP算法,竟然也是N^3的算法.不过感觉写太多了. 无奈之下,在最后的上传时限,只好用C写了个,最笨的程序交上去了. 源程序 #include fstream.h #include iomanip.h #include iostream.h #include string.h const N=100000; int main() { ifstream input(input.txt); ofstream output(output.txt); char a[N]; int i,j,n,t,p,max=0; inputa; n=strlen(a); for(i=0;in;i++) { for(j=i+1;jn;j++) { t=0; while(a[i+t]==a[j+t](j+t)n) t++; if(tmax) {
原创力文档

文档评论(0)