POJ 3080 多个串最长公共子序列
求多个串最长公共子序列,字典序最小输出。枚举剪枝+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 多个串最长公共子序列的更多相关文章
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 56150 Accepted: 19398 Desc ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- POJ 1458 Common Subsequence 【最长公共子序列】
解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...
- POJ 1458 Common Subsequence(最长公共子序列)
题目链接Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description A subsequence o ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...
- POJ 1159 Palindrome(最长公共子序列)
Palindrome [题目链接]Palindrome [题目类型]最长公共子序列 &题解: 你做的操作只能是插入字符,但是你要使最后palindrome,插入了之后就相当于抵消了,所以就和在 ...
- POJ 1458 最长公共子序列(dp)
POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...
随机推荐
- chrom控制台常用方法
console.assert对输入的表达式进行断言,只有表达式为false时,才输出相应的信息到控制台 . console.count(这个方法非常实用哦)当你想统计代码被执行的次数 console. ...
- 产生式模型(生成式模型)与判别式模型<转载>
转自http://dongzipnf.blog.sohu.com/189983746.html 产生式模型与判别式模型 产生式模型(Generative Model)与判别式模型(Discrimiti ...
- 国庆集训 || Wannafly Day4
链接:https://www.nowcoder.com/acm/contest/205#question 一场题面非常 有趣 但是题目非常 不友好的比赛 QAQ L.数论之神 思维(?) 题意:求 ...
- shell脚本,计算创建100个文件所用多少时间。
[root@localhost mulu]# ls [root@localhost mulu]# `; do touch file$i; done real 0m0.104s user 0m0.012 ...
- 【技巧:字符串同构】Avendesora
判断字符串“同构”的技巧 题目大意 给定A,B两个序列,要求B在A中出现的次数以及位置.定义字符变换:把所有相同的字符变为另一种字符:两个字符串相等:当且仅当一个字符串可以在若干次字符变换之后变为另一 ...
- RESTful介绍
web框架的本质: socket服务端与浏览器的通信 socket(套接字):进程间的一种通信方式 socket服务端功能划分: a.负责与浏览器收发消息(socket通信) --- ...
- 【mysql】配置 选项文件
在Windows中,MySQL程序从以下文件读取启动选项: 文件名 目的 WINDIR\my.ini 全局选项 C:\my.cnf 全局选项 INSTALLDIR\my.ini 全局选项 defaul ...
- The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...
- 快速入门Sklearn
主要确定sklearn的基本流程,然后把sklearn当做螺丝刀来用就行了,需要什么查什么. 基本流程 首先我们回顾一下机器学习的基本流程: 特征工程,包括了数据清洗,数据标准版化,特征选取,特征降维 ...
- 在html页面中使用js变量
Method 1: <a id="xxxx">xxxxxxxxxxxxxxxxxx</a> <script type="text/jav ...