Approximate test instructions:
A sequence of n-60 DNA genes (a adenine g guanine t-cytosine C cytosine) was given to find their longest common subsequence
Using a suffix array to resolve
1#include <stdio.h>2#include <string.h>3 Charstr[6200],res[6200];4 intnum[6200],loc[6200];5 intsa[6200],rank[6200],height[6200];6 intwa[6200],wb[6200],wv[6200],wd[6200];7 intvis[6200];8 intSeq_num;9 intcmpint(RNintAintBintl) {Ten returnr[a]==r[b]&&r[a+l]==r[b+l]; One } A voidDA (int*r,intNintm) { - inti,j,p,*x=wa,*y=wb,*T; - for(i=0; i<m;i++) wd[i]=0; the for(i=0; i<n;i++) wd[x[i]=r[i]]++; - for(i=1; i<m;i++) wd[i]+=wd[i-1]; - for(i=n-1; i>=0; i--) sa[--wd[x[i]]]=i; - for(j=1, p=1;p <n;j*=2, m=p) { + for(p=0, i=n-j;i<n;i++) y[p++]=i; - for(i=0; i<n;i++)if(sa[i]>=j) y[p++] = Sa[i]-J; + for(i=0; i<n;i++) wv[i]=X[y[i]]; A for(i=0; i<m;i++) wd[i]=0; at for(i=0; i<n;i++) wd[wv[i]]++; - for(i=1; i<m;i++) wd[i]+=wd[i-1]; - for(i=n-1; i>=0; i--) sa[--wd[wv[i]]]=Y[i]; - for(t=x,x=y,y=t,p=1, x[sa[0]]=0, i=1; i<n;i++){ -X[SA[I]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; - } in } - } to voidCalheight (int*r,intN) { + inti,j,k=0; - for(i=1; i<=n;i++) rank[sa[i]]=i; the for(i=0; i<n;height[rank[i++]]=k) { * for(k?k--:0, j=sa[rank[i]-1];r[i+k]==r[j+k];k++); $ }Panax Notoginseng } - intCheckintMidintLen) { the intI,j,tot; +tot=0; Amemset (Vis,0,sizeof(Vis)); the for(i=2; i<=len;i++){ + if(height[i]<mid) { -memset (Vis,0,sizeof(Vis)); $tot=0; $}Else{ - if(!vis[loc[sa[i-1]]]){ -vis[loc[sa[i-1]]]=1; thetot++; - }Wuyi if(!Vis[loc[sa[i]]) { thevis[loc[sa[i]]]=1; -tot++; Wu } - if(tot==seq_num) { About for(j=0; j<mid;j++){ $res[j]=num[sa[i]+j]+'A'-1; -}res[mid]=' /'; - return 1; - } A } + } the return 0; - } $ intMain () { the intCase_num,n,sp,ans; thescanf"%d",&case_num); the for(intI=0; i<case_num;i++){ thescanf"%d",&seq_num); -n=0; insp= in; theans=0; the for(intj=0; j<seq_num;j++){ Aboutscanf"%s", str); the for(intk=0;k< -; k++){ theloc[n]=J; thenum[n++]=str[k]-'A'+1; + } -loc[n]=sp; thenum[n++]=sp++;Bayi } thenum[n]=0; theDA (num,n+1, SP); - calheight (num,n); - intleft=0, right= -, mid; the the while(right>=Left ) { theMid= (Right+left)/2; the inttt=check (mid,n); - if(TT) { theLeft=mid+1; theans=mid; the}Else{94right=mid-1; the } the } the if(ans>=3){98printf"%s\n", res); About}Else{ -printf"no significant commonalities\n");101 }102 }103 return 0;104}
Attached: original topic
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 14020 |
|
Accepted: 6227 |
Description
The Genographic Project is a-partnership between IBM and the National Geographic Society that's analyzing DNA fr Om Hundreds of thousands of contributors to map how the Earth was populated.
As an IBM researcher, you had been tasked with writing a program that would find commonalities amongst given snippets of D NA that can is 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 was found in the molecule. There is 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 would begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:
- A single Positive An integer m (2 <= m <=) indicating the number of the base sequences in this DataSet.
- M lines each containing a single base sequence consisting of 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" in Stead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical or Der.
Sample Input
32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A3gataccagataccagataccagataccagataccagataccagataccagataccagatagatactagatactagatactagatactaaaggaaagggaaaaggggaaaaagggggaaa Agataccagataccagataccagataccaaaggaaagggaaaaggggaaaaagggggaaaa3catcatcatcccccccccccccccccccccccccccccccccccccccccccccccccc Cacatcatcataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacatcatcatttttttttttttttttttttttttttttttttttttttttttttttttt
Sample Output
No significant commonalitiesagataccatcatcat
Blue jeans-poj 3080 (suffix array)