大致题意:

给出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. ajaxfileupload-上传文件示例

    1.引用文件 ajaxfileupload.js @{ ViewBag.Title = "数据导入"; Layout = "~/Views/Shared/_IndexLa ...

  2. SQL server 2008 安装问题解决 转

    http://www.cnblogs.com/Hackerman/p/4472811.html   安装sqlserver2008 出现的一些问题解决方法 1,安装sqlserver的时候出现如下图所 ...

  3. Android Design Support Library介绍之:环境搭建

    在2015年的GoogleIO大会上.具体的Material Design设计规范出炉了.全新的Android Design Support Library 格.更让人开心的是,这些很酷的风格能够通过 ...

  4. t-SNE和LDA PCA的学习

    t-SNE 可以看这篇文章: http://bindog.github.io/blog/2016/06/04/from-sne-to-tsne-to-largevis/ LDA可以看这篇文章: htt ...

  5. Less使用说明

    使用koala编译 Koala 是一款由国人开发的开源预处理语言图形编译工具,目前已支持 Less.Sass.Compass 与CoffeeScript. 目前支持以下系统:Windows,Mac, ...

  6. js 正则只允许小写字母、数字、点、中短划线

    正则表达式如下: /^[a-z0-9\.-]*$/g 可用如下语句验证: alert(/^[a-z0-9\.-]*$/g.test('abc123.45a-b')); //true alert(/^[ ...

  7. Idea闪退问题-内存不能给太大

    Idea闪退问题-内存不能给太大 学习了:https://blog.csdn.net/qq_17776287/article/details/77529455 学习了:https://blog.csd ...

  8. Android——DEBUG 堆栈

    当android系统执行出现死机等致命错误的时候.通常会有堆栈的DEBUG信息打印,一般直接看根本看不出问题是出在哪里!记录下我android4.2 的DEBUG 堆栈log的方法. 撰写不易,转载请 ...

  9. Linux启动U盘制作

    Linux目前最好的u盘启动工具之一,下面介绍它的用法,首先下载Linux live OK了,一步一步跟我步骤走! 启动时,选择需要用的U盘 步骤二,就选择安装源即可(一般为ISO文件) 最后进行步骤 ...

  10. CentOS 6.4 图文安装教程(有些设置大部分教程没出现过)

    http://www.jb51.net/os/78318.html CentOS 6.4 下载地址: http://www.jb51.net/softs/78243.html 1.首先,要有一张Cen ...