POJ 3080 Blue Jeans

Source: Internet
Author: User

Blue JeansTime Limit: 1000 MS Memory Limit: 65536 KTotal Submissions: 8880 Accepted: 3734 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 cocould be represented as TAGACC. given a set of DNA base sequences, determ Ine the longest series of bases that occurs in all of the sequences. 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 bas Es. 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 32 GATACCAGAT Bytes Export Output no significant commonalitiesAGATACCATCATCATSource South Central USA 2006: KMP is used to take a string, simulate each string, and compare the strings with kmp and other strings. [Cpp] # include <iostream> # include <cstdio> # include <cstring> using namespace std; char s1 [50] [100]; char s2 [100]; char res [100]; int next [100]; int len; int main () {int KMP (char s3 [100], int l); int I, j, n, m, s, t, x, sum, k; bool find; int l; len = 60; scanf ("% d", & t); while (t --) {scanf ("% d", & n); for (I = 0; I <= n-1; I ++) {scanf ("% s ", s1 [I]);} find = false; sum = 0; for (I = 0; I <= len-1; I ++) {if (I + 3) <= len) {for (l = 3; I + l <= len; l ++) {x = 0; for (j = 0; j <= L-1; j ++) {s2 [j] = s1 [0] [j + I];} s2 [j] = '\ 0'; for (j = 1; j <= n-1; j ++) {k = KMP (s1 [j], l); if (! K) {break ;}} if (j! = N) {break;} else {find = true; if (sum <l) {sum = l; strcpy (res, s2);} else if (sum = l) {if (strcmp (res, s2)> 0) {strcpy (res, s2) ;}}}} if (find = false) {printf ("no significant commonalities \ n");} else {printf ("% s \ n", res) ;}} return 0;} void get_next (int l) {int I, j; next [0] =-1; next [1] = 0; j = 0; for (I = 2; I <= l ;) {if (j =-1 | s2 [I-1] = s2 [j]) {I ++; j ++; if (s2 [I-1] = s2 [j]) {next [I-1] = next [j];} else {Next [I-1] = j;} else if (s2 [I-1]! = S2 [j]) {j = next [j] ;}} int KMP (char s3 [100], int l) {int l2 = l, I, j; int l3 = len; get_next (l2); I = j = 0; while (I <= l3-1) {if (j =-1 | s2 [j] = s3 [I]) {I ++; j ++;} else if (s2 [j]! = S3 [I]) {j = next [j];} if (j = l2) {return 1 ;}} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.