博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher I - Blue Jeans POJ - 3080 (找多个字符串的最长公共子序列,字典序最小)...
阅读量:4557 次
发布时间:2019-06-08

本文共 2947 字,大约阅读时间需要 9 分钟。

I - Blue Jeans POJ - 3080

题目链接:

题目:

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.
As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers.
A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC.
Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.
Input
Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:
  • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 bases.
Output
For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.
Sample Input
32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalitiesAGATACCATCATCAT 题意:T组数据,每组包含一个n,后有n个字符串,求出这n个字符串最长子序列,并且字典序最小 思路:利用Kmp来判断是否为其他字符串的子序列,然后从第一个字符串开始找子串,判断子串是否为其他n-1的子串,是的话就是了, 再初始化一个字符串,因为要字典序最小,所以每次取长度相等时的min就行了,详解见代码
// // Created by HJYL on 2019/8/16.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn=1e6+10;int nextt[maxn];string str[maxn];void getnext(string str)//KMP求next数组{ int i=0,j=-1; nextt[0]=-1; int len=str.size(); while(i
>str[i]; string ans="";//结果字符串初始化,方便找字典序最小的 for(int i=1;i<=str[0].size();i++)//以第一个字符串开始 { for(int j=0;j<=str[0].size()-i;j++)//暴力找 { string op=str[0].substr(j,i);//还是初始化 getnext(op); bool falge=false; for(int k=1;k

 

 

转载于:https://www.cnblogs.com/Vampire6/p/11364145.html

你可能感兴趣的文章
retinex相关代码汇总
查看>>
Cortex-M3 异常返回值EXC_RETURN
查看>>
Objective-C语言-内存管理
查看>>
迅雷API:实现文件下载
查看>>
Socket编程实践(2) Socket API 与 简单例程
查看>>
print 与标准输出
查看>>
pytest单元测试框架(day01)
查看>>
利用Azure Automation实现云端自动化运维(2)
查看>>
Linux学习说明
查看>>
【网络流24题】负载平衡问题(费用流)
查看>>
bzoj 3507 DP+哈希
查看>>
递归问题==优化 还有数据库sqlreader
查看>>
IOS第四天(2:字典转模型plist)
查看>>
什么是数据集
查看>>
Android开发数据库三层应用-DataSnap
查看>>
关于setTimeout运行机制
查看>>
2019 Multi-University Training Contest 4
查看>>
学号 《信息安全系统设计基础》第7周学习总结(一)
查看>>
POJ1741Tree [点分治]【学习笔记】
查看>>
BZOJ 3238: [Ahoi2013]差异 [后缀自动机]
查看>>