DNA sequence
Time Limit: 15000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 4217 accepted submission (s): 2020
Problem descriptionthe twenty-first century is a biology-technology developing century. we know that a gene is made of DNA. the nucleus otide bases from which DNA is built are a (adenine), C (cytosine), g (guanine), and T (thymine ). finding the longest common subsequence between DNA/protein sequences is one of the basic problems in modern computational molecular biology. but this problem is a little different. given several DNA sequences, you are asked to make a shortest sequence from them so that each of the given sequence is the subsequence of it.
For example, given "acgt", "atgc", "cgtt" and "cagt", you can make a sequence in the following way. it is the shortest but may not the only one.
Inputthe first line is the test case number t. then T test cases follow. in each case, the first line is an integer N (1 <= n <= 8) represents number of the DNA sequences. the following K lines contain the K sequences, one per line. assuming that the length of any sequence is between 1 and 5.
Outputfor each test case, print a line containing the length of the shortest sequence that can be made from these sequences.
Sample input14acgtatgccgttcagt
Sample output8
Authorll
Sourcehdu 2006-12 Programming Contest
Recommendll: now we have given several DNA sequences. Please construct a shortest DNA sequence so that all the given DNA sequences are its subsequences. For example, given "acgt", "atgc", "cgtt", "cagt", you can construct a shortest sequence as "acagtgct", but note that, this is not the only solution to this problem. Idea: * If IDA has the current Length + the longest construction length <the maximum depth of iteration, return performs a good pruning accode.
# Include <iostream> # include <cstdio> # include <cstdlib> # include <sstream> # include <cstring> # include <string> # include <vector> # include <set> # include <stack> # include <queue> # include <map> # include <cmath> # include <algorithm> using namespace STD; # define INF 0x3f3f3f # define ll long # define max_n 1000005 # define gcd (a, B) _ gcd (a, B) # define MEM (A, X) memset (A, X, sizeof (A) # define mid (A, B) A + B/2 # define STOL (a) atoi (. c _ STR () // string to longstring temp [10]; string c = "acgt"; int POS [10]; int Len [10]; int deep; int N; int ans () {int maxn = 0; For (INT I = 0; I <n; I ++) {maxn = max (maxn, len [I]-pos [I]);} return maxn;} int DFS (INT step) {If (Step + ans ()> deep) return 0; If (! Ans () // The constructed sequence contains all the sequences return 1; int temp1 [10]; for (INT I = 0; I <4; I ++) {int flag = 0; For (Int J = 0; j <n; j ++) temp1 [J] = POS [J]; for (Int J = 0; j <n; j ++) {If (temp [J] [POS [J] = C [I]) {flag = 1; pos [J] ++ ;}}if (FLAG) {If (DFS (Step + 1) return 1; for (Int J = 0; j <N; j ++) POS [J] = temp1 [J] ;}} return 0 ;}int main () {// freopen ("d :\\ in.txt ", "r", stdin); int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); deep = 0; For (INT I = 0; I <n; I ++) {CIN> temp [I]; Len [I] = temp [I]. length (); POS [I] = 0; deep = max (deep, Len [I]);} while (1) {If (DFS (0) break; + deep;} printf ("% d \ n", deep);} return 0 ;}
DNA sequence HDU-1, 1560