大致题意:

给出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. 线程协作-CountDownLatch

    CountDownLatch允许一个或多个线程等待其他线程完成操作.

  2. javolution-core-java-6.1.0.jar 的使用

    官方网址:http://javolution.org/apidocs/javolution/io/Struct.html 第一步:导包 第二步:创建继承的结构体 结构体定义如下所示: public c ...

  3. 【InteillJ IDEA】Git的安装+同步项目到GitHub上

    需要的工具: 1.InteillJ IDEA 2.Git 3.GitHub帐号 步骤: 1.下载Git 下载地址:https://git-scm.com/downloads 安装完成后 勾选Launc ...

  4. CSS:display:table

    使用display:table 垂直居中需要结合display:table-cell; 和vertical-align:middle; <!DOCTYPE html> <html l ...

  5. 利用LogParser分析IIS日志

    LogParser是微软官方出品的用于读取分析IIS日志的工具,使用类SQL语句过滤文本日志内容,并可将内容导出到csv.sqlserver作进一步分析    下载地址:http://www.micr ...

  6. canvas如何兼容IE8

    大家都知道canvas是个非常好玩的东西,但是IE9以下的浏览器不支持,有时候业务需求必须用到canvas,且又要求兼容IE8浏览器,那怎么办呢? 1.添加对html5的支持:<!--[if I ...

  7. 深度剖析OpenGL ES中的多线程和多窗口渲染技术

    由 创新网小编 于 星期五, 2014-04-11 14:56 发表 移动设备中的CPU和GPU已经变得很强大,到处都是配备一个或多个高分辨率屏幕的设备,需要使用带有图形驱动器的复杂交互也日益增加.在 ...

  8. virtualbox 设置windows 于ubuntu虚拟机共享文件夹

    会弹出错误, .. ..还是会有错误, modprobe       -a vboxsf 之后就可以挂载成功了!!

  9. [Flutter] Creating & Updating State in a Flutter Application

    To create a Stateful widget: 1. Create a StatefulWidget 2. Create a State class SGreeting extends St ...

  10. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-点击运行按钮进入到运行状态报错Error starting TwinCAT System怎么办 AdsWarning1823怎么办

    一般提示如下   点击Device,然后选中当前真正连接到的网卡   一般是由于重装系统之后,没有把本来是realtime capable的设备Install,所以找不到支持EtherCAT的设备导致 ...