POJ 1226(最长公共子串含逆序)
来源:互联网 发布:java执行另一个项目 编辑:程序博客网 时间:2024/06/13 06:43
Language:
Substrings
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9639 Accepted: 3319
Description
请找出一些串的最长‘正/逆‘子串,使它为所有的串的子串(即使是逆序也认为包含).
Input
第一行为数据数t,(1 <= t <= 10),
对每组数据而言:第一行为字符串个数 n (1 <= n <= 100),接下来n行为字符串(长度不超过100) .
Output
每行一个数,表示最长'正/逆‘子串的长度。
Sample Input
23ABCDBCDFFBRCD2roseorchid
Sample Output
22
Source
Tehran 2002 Preliminary
还是KMP,先在第一个串中枚举串,之后考察它是否是其它串的'正/逆'子串。Program P1226;const maxn=100; maxt=10;var tt,n,m,i,j,k,ans:longint; flag:boolean; a:array[1..maxn] of string; p:string; next:array[1..maxn] of longint;function kmp(a,b:string):boolean;var i,j,n,m:longint;begin i:=1;j:=0;next[1]:=0; n:=length(a); m:=length(b); while (i<m) do begin if (j=0) or (b[i]=b[j]) then begin inc(i);inc(j); if (b[i]<>b[j]) then next[i]:=j else next[i]:=next[j]; end else j:=next[j]; end; i:=0;j:=0; while (i<=n) and (j<=m) do begin if (j=0) or (a[i]=b[j]) then begin inc(i);inc(j); end else j:=next[j]; end; if (j>m) then exit(true); exit(false);end;function ob_s(a:string):string;var i,j,n:longint;begin ob_s:=''; n:=length(a); for i:=n downto 1 do ob_s:=ob_s+a[i];end;function compare(a,b:string):boolean;var n,m:longint;begin n:=length(a);m:=length(b); if (n<>m) then exit(n<m); for i:=1 to n do if a[i]<>b[i] then exit(a[i]<b[i]); exit(false);end;begin readln(tt); while (tt>0) do begin ans:=0; readln(n); for i:=1 to n do readln(a[i]); for i:=1 to length(a[1]) do for j:=i to length(a[1]) do begin p:=copy(a[1],i,j-i+1); flag:=true; for k:=2 to n do begin if not((kmp(a[k],p) or kmp(a[k],ob_s(p)))) then begin flag:=false; break; end; end; if flag and (length(p)>ans) then ans:=length(p); end; writeln(ans); dec(tt); end;end.
- POJ 1226(最长公共子串含逆序)
- POJ 3080(最长公共子串)
- POJ 1080(最长公共子序列)
- POJ 1548 (最长公共子串)
- POJ 1458(最长公共子序列)
- POJ 3356 (最长公共子序列)
- POJ 2250Compromise(DP最长子公共子序列)
- POJ 2774 Long Long Message(最长公共子串)
- poj 1458 LCS(最长公共子序)
- poj 1458最长公共子序列(LCS)
- poj 2250 Compromise(LCS,最长公共子序列)
- POJ 3080 Blue Jeans (求最长公共字符串)
- 【mark】最长公共子序列(poj 1458+hdu 1159)
- poj 2127(最长公共上升子序列)
- poj 3080 Blue Jeans(最长公共子串)
- POJ 3356 AGTC(最长公共子序列)
- POJ 3356 AGTC(最长公共子序列)
- POJ 1458 Common Subsequence(最长公共子序列问题)
- python闭包 unboundLocalError错误解决----转载
- 快速排序
- 【转】animation-list旋转的地球以及Timer的使用
- 使用SetEnvironmentVariable调整应用程序环境变量中的path设置
- Android问答
- POJ 1226(最长公共子串含逆序)
- How to setup Wiki on CentOS
- Windows下安装Object-C开发环境
- P制,N制,奇场,偶场,隔行扫描,逐行扫描
- 【2013 中科大洋 笔试】父类指针指向子类--delete父类时。。。。。析构,构造。
- dedecms 目录结构
- JavaScript库EASELJS的第一眼映像(三)
- linux报文件数打开过多too many open files
- C/C++中内存释放及内存泄露的检测