大致题意:

给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列

使用后缀数组解决

 #include<stdio.h>
#include<string.h>
char str[],res[];
int num[],loc[];
int sa[],rank[],height[];
int wa[],wb[],wv[],wd[];
int vis[];
int seq_num;
int cmp(int *r,int a,int b,int l){
return r[a]==r[b]&&r[a+l]==r[b+l];
}
void DA(int *r,int n,int m){
int i,j,p,*x=wa,*y=wb,*t;
for(i=;i<m;i++)wd[i]=;
for(i=;i<n;i++)wd[x[i]=r[i]]++;
for(i=;i<m;i++)wd[i]+=wd[i-];
for(i=n-;i>=;i--) sa[--wd[x[i]]]=i;
for(j=,p=;p<n;j*=,m=p){
for(p=,i=n-j;i<n;i++) y[p++]=i;
for(i=;i<n;i++) if(sa[i]>=j) y[p++] = sa[i] -j;
for(i=;i<n;i++)wv[i]=x[y[i]];
for(i=;i<m;i++) wd[i]=;
for(i=;i<n;i++)wd[wv[i]]++;
for(i=;i<m;i++)wd[i]+=wd[i-];
for(i=n-;i>=;i--) sa[--wd[wv[i]]]=y[i];
for(t=x,x=y,y=t,p=,x[sa[]]=,i=;i<n;i++){
x[sa[i]]=cmp(y,sa[i-],sa[i],j)?p-:p++;
}
}
}
void calHeight(int *r,int n){
int i,j,k=;
for(i=;i<=n;i++)rank[sa[i]]=i;
for(i=;i<n;height[rank[i++]]=k){
for(k?k--:,j=sa[rank[i]-];r[i+k]==r[j+k];k++);
}
}
int check(int mid,int len){
int i,j,tot;
tot=;
memset(vis,,sizeof(vis));
for(i=;i<=len;i++){
if(height[i]<mid){
memset(vis,,sizeof(vis));
tot=;
}else{
if(!vis[loc[sa[i-]]]){
vis[loc[sa[i-]]]=;
tot++;
}
if(!vis[loc[sa[i]]]){
vis[loc[sa[i]]]=;
tot++;
}
if(tot==seq_num){
for(j=;j<mid;j++){
res[j]=num[sa[i]+j]+'A'-;
}res[mid]='\0';
return ;
}
}
}
return ;
}
int main() {
int case_num,n,sp,ans;
scanf("%d",&case_num);
for(int i=;i<case_num;i++){
scanf("%d",&seq_num);
n=;
sp=;
ans=;
for(int j=;j<seq_num;j++){
scanf("%s",str);
for(int k=;k<;k++){
loc[n]=j;
num[n++]=str[k]-'A'+;
}
loc[n]=sp;
num[n++]=sp++;
}
num[n]=;
DA(num,n+,sp);
calHeight(num,n);
int left=,right=,mid; while(right>=left){
mid=(right+left)/;
int tt=check(mid,n);
if(tt){
left=mid+;
ans=mid;
}else{
right=mid-;
}
}
if(ans>=){
printf("%s\n",res);
}else{
printf("no significant commonalities\n");
}
}
return ;
}
 
附:原题目
 
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14020   Accepted: 6227

Description

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

3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalities
AGATAC
CATCATCAT

Blue Jeans - poj 3080(后缀数组)的更多相关文章

  1. (字符串 KMP)Blue Jeans -- POJ -- 3080:

    链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...

  2. POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)

    多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...

  3. POJ 3080 后缀数组/KMP

    题目链接:http://poj.org/problem?id=3080 题意:给定n个DNA串,求最长公共子串.如果最长公共子串的长度小于3时输出no significant commonalitie ...

  4. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  5. Blue Jeans - POJ 3080(多串的共同子串)

    题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个.   分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...

  6. Blue Jeans POJ 3080 寻找多个串的最长相同子串

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  7. poj 3693 后缀数组 重复次数最多的连续重复子串

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8669   Acc ...

  8. POJ 3415 后缀数组

    题目链接:http://poj.org/problem?id=3415 题意:给定2个串[A串和B串],求两个串公共子串长度大于等于k的个数. 思路:首先是两个字符串的问题.所以想用一个'#'把两个字 ...

  9. POJ 3450 后缀数组/KMP

    题目链接:http://poj.org/problem?id=3450 题意:给定n个字符串,求n个字符串的最长公共子串,无解输出IDENTITY LOST,否则最长的公共子串.有多组解时输出字典序最 ...

随机推荐

  1. 【C语言】 Linux下编译提示pow未定义引用

    如下代码: #include <stdio.h> // 调用基本输入输出函数库 #include <math.h> #define PI 3.14 // 定义常量 float ...

  2. Zookeeper的功能以及工作原理(转)

    本文转自https://www.cnblogs.com/felixzh/p/5869212.html Zookeeper的功能以及工作原理   1.ZooKeeper是什么?ZooKeeper是一个分 ...

  3. 【java】乱码处理+编码转化+判断字符串编码方式

    之前有一篇是修改IDE的编码,服务器的编码等处理乱码,但是在所有环境因素上,保证了编码方式之后,也会有前台传递给后台[get方式提交]传递给后台的编码方式是非UTF-8的,也会有例如FTP服务器的编码 ...

  4. Array.apply 方法的使用

    Array.apply(null, {length: 5}) length为特殊字段,意思是生成一个长度为5的数组,由于没赋值,所以都是undefined; 如果要赋值,可以这样 console.lo ...

  5. easyui dialog 按钮动态命名

    1.方法一: /** * grid新增 * 弹框并且获取支付类型 */ function gridAdd() { var dlg = $('#mydialog').dialog({ title : & ...

  6. python3发送html格式的邮件

    def send_mail(to_list, sub, content, attpath): me = "*******" + "<" + mail_us ...

  7. 【转载】网络攻击技术(三)——Denial Of Service & 哈希相关 & PHP语言 & Java语言

    找到了这个系列的原始作者: http://www.cnblogs.com/rush/archive/2012/02/05/2339037.html 最近网络安全成了一个焦点,除了国内明文密码的安全事件 ...

  8. scrapy-splash抓取动态数据例子十

    一.介绍 本例子用scrapy-splash抓取活动行网站给定关键字抓取活动信息. 给定关键字:数字:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信息 ...

  9. 总结对Docker这个东西的想法

    记得一开始的时候,还只能在一些网站上看到关于Docker零星的一些消息,之后的不久,有关Docker消息就遍布网络. 是什么因素让Docker火起来的? 或者说什么原因促使大家都对Docker感兴趣并 ...

  10. easyUI表头样式

    easyUI表头样式 学习了:https://blog.csdn.net/lucasli2016/article/details/53606609 easyUI的样式定义在easyui.css中 表头 ...