[POJ3080] Blue Jeans

传送门

http://poj.org/problem?id=3080

题目大意

给定n个串,询问最长公共字串,长度>=3,长度相同为字典序最小

题解

KMP+暴力枚举

var
 x:array[0..20]of string;
 next:array[0..100]of longint;
 i,j,k,l,o,p,t,tt,ttt:longint;
 n,m,anss:longint;
 a,ans:string;
begin
 readln(t);
 for l:=1 to t do
  begin
   readln(n);
   for i:=1 to n do
    readln(x[i]);
   ans:='no significant commonalities'; anss:=0;
   for o:=3 to 60 do
    for p:=1 to 60-o+1 do
     begin
      a:=copy(x[1],p,o); m:=length(a);
      next[1]:=0; j:=0;
      for i:=2 to m do
       begin
        while (j>0)and(a[j+1]<>a[i]) do j:=next[j];
        if a[j+1]=a[i] then inc(j);
        next[i]:=j;
       end;
      tt:=1;
      for k:=2 to n do
       begin
        j:=0; ttt:=0;
        for i:=1 to 60 do
         begin
          while (j>0)and(x[k][i]<>a[j+1]) do j:=next[j];
          if x[k][i]=a[j+1] then inc(j);
          if j=m then begin ttt:=1; break; end;
         end;
        if ttt=0 then begin tt:=0; break; end;
       end;
      if (tt=1)and((anss<o)or(anss=o)and(a<ans)) then begin ans:=a; anss:=o; end;
     end;
   writeln(ans);
  end;
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值