[POJ3080] Blue Jeans
2015-12-16 14:50
330 查看
传送门
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.
相关文章推荐
- Juery On事件的 事件触发流程
- easyui 多行文本框 Multiline TextBox
- [转]SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery)
- 基于MVC4+EasyUI的Web开发框架形成之旅之界面控件的使用
- Android UiAutomator快速调试
- NSURLRequest 数据请求
- Android UI系列-----时间、日期、Toasts和进度条Dialog
- UI12-uiPickerView
- UI11-源代码管理工具概述
- 创建quickstart报错
- Spark SQL 之 Migration Guide
- UIProgressView的使用
- iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)
- [Elasticsearch] 控制相关度 (五) - function_score查询及field_value_factor,boost_mode,max_mode参数
- leetcode -- Unique Paths I &&II-- 典型DP 题目,简单要看
- 开源webUI自动测试工具利器Sahi
- UITableView学习笔记
- UUID随机字符串
- 折叠UITableView分组实现方法
- iOS学习之UICollectionVuew基本使用