求多个串最长公共子序列,字典序最小输出。枚举剪枝+kmp.比较简单,我用find直接查找16ms

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s[61];
int main()
{
int ta;
cin>>ta;
int n;
while(ta--)
{
cin>>n;
string ans;
for(int i=0;i<n;i++)
cin>>s[i];
int len=s[0].size();
int max=2;
for(int i=0;i<=len-max;i++) //最优化剪枝
{
for(int j=len;j>=i+max;j--)
{
string ts(&s[0][i],&s[0][j]); //对象的赋值
int mark=1;
for(int k=1;k<n;k++)
{
if(s[k].find(ts)==4294967295) //找不到
{
mark=0;
break;
}
}
if(mark&&ts.size()>=max)
{
if(ts.size()>max)
{
max=ts.size();
ans=ts;
}
else
if(ts<ans)
{
ans=ts;
}
}
}
}
if(max==2)
cout<<"no significant commonalities"<<endl;
else cout<<ans<<endl; }
}

POJ 3080 多个串最长公共子序列的更多相关文章

  1. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  2. POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56150   Accepted: 19398 Desc ...

  3. poj 1080 Human Gene Functions (最长公共子序列变形)

    题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...

  4. POJ 1458 Common Subsequence 【最长公共子序列】

    解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc         abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...

  5. POJ 1458 Common Subsequence(最长公共子序列)

    题目链接Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description A subsequence o ...

  6. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  7. POJ - 1458 Common Subsequence DP最长公共子序列(LCS)

    Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...

  8. POJ 1159 Palindrome(最长公共子序列)

    Palindrome [题目链接]Palindrome [题目类型]最长公共子序列 &题解: 你做的操作只能是插入字符,但是你要使最后palindrome,插入了之后就相当于抵消了,所以就和在 ...

  9. POJ 1458 最长公共子序列(dp)

    POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...

随机推荐

  1. WINDOWS-API:操作网络映射盘-WNetAddConnection2

    首先在VC项目属性,开发依赖项里添加MPR.lib:然后,配置文件里填入以下信息.  //本地映射盘符 MapDriver=T: //目标根目录 //MapSharedPath=\\192.168.0 ...

  2. 2019 opensuse linux Eclipse

    无法启动解决 eclipse.ini 尾部追加 --add-modules=ALL-SYSTEM /etc/hosts 追加 127.0.0.1 linux-xapw http://dl.google ...

  3. PHP的PDF扩展库TCPDF将中文字体设置为内嵌字体的方法

    1. 下载要设置的字体,如名为simfang.ttf,放在./vendor/tecnickcom/tcpdf/tools目录中 2.在tools目录中按住shift,点击鼠标右键,点击“在此处打开命令 ...

  4. 2017年网络空间安全技术大赛部分writeup

    作为一个bin小子,这次一个bin都没做出来,我很羞愧. 0x00 拯救鲁班七号 具体操作不多说,直接进入反编译源码阶段 可以看到,只要2处的str等于a就可以了,而str是由1处的checkPass ...

  5. bootstrap 翻页(对齐的链接)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  6. ios坐标系统

    在写程序的时候发现,iOS下的坐标.位置很容易弄乱,特别是在不同的坐标系统中,必须完成弄明白一些概念才能做相应的变化,例如CoreImage和UIView的坐标系统就截然不同,一个是以屏幕的左上角为原 ...

  7. 使Linux支持exFAT和NTFS格式的磁盘

    Linux支持exFAT和NTFS Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最 ...

  8. CSS3中制作倒影box-reflect

    目前仅在Chrome.Safari和Opera浏览器下支持 box-reflect:none | <direction> <offset>? <mask-box-imag ...

  9. grep理解

    http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html部分摘录于此 grep与正规表达式  字符类 字符类的搜索:如果我想要搜 ...

  10. Codeforces Round #879 (Div. 2) C. Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...