大致题意:

给出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. 如何提高码农产量,基于ASP.NET MVC的敏捷开发框架之工作流开发随笔三

    前言 “厂长,APP的那几个功能都差不多了,接下来要做工作流,工作流这东西我完全没概念啊.” “查尔斯,一般来说工作流就是指将指定的数据.文件.任务按照预定的规则进行传递流转.比如说你要请假,拿个请假 ...

  2. 日积月累--exception记录

    关于Android的sqlite数据类型text长度限制的问题? 这也许不能称为一个bug,但是比较坑,所以贴在了这里.在Android的sqlite中存储一个字符串,发现总是数据丢失,我去查询sql ...

  3. OpenStack制作Windows 2008 KVM镜像

    1.下载驱动程序 [root@linux-node1 ~]# cd /usr/local/src [root@linux-node1 src]# wget https://launchpad.net/ ...

  4. 接入WebSocket记录 + 一些个人经验

    闲扯 WebSocket 以前没用过,之前写过一篇博客是基于原生socket的(查看)比较复杂,慎入.今天另外一个APP需要接websocket了,然后便找到了facebook的 SocketRock ...

  5. Linux 动态库 静态库

    什么是库 本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.由于windows和Linux的本质不同,因此二者库的二进制是不兼容的.Linux操作系统支持的库函数分为静态库和动态库 ...

  6. Oracle架构全图

  7. vue2计算属性computed

    详见vue2.0 API<计算属性> 需求: 模板内的表达式是非常便利的,但是它们实际上只用于简单的运算.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div id=&qu ...

  8. mycat读写分离与主从切换

    1, 分库分表的优缺点.以及为什么分表方式无法成为主流? 分表:在台server上,长处是易维护,相似表分区.缺点是在一台dbserver上.无法分担IO.负载集中. 分库:在多台server上,长处 ...

  9. 【POJ 1080】 Human Gene Functions

    [POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...

  10. Srping AOP xml方式

      使用aop需要: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...