DNA sequencetime limit:15000/5000ms (java/other) Memory limit:32768/32768k (Java/other) total submission (s): Ac cepted Submission (s): 7font:times New Roman | Verdana | Georgiafont Size:←→problem DescriptionThe Twenty-first century is a biology-technology developing century. We know a gene is made of DNA. The nucleotide bases from which DNA was built is 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. Problem is a little different. Given Several DNA sequences, you be asked to make a shortest sequence from them so this 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. It is the shortest and may was not the only one.
Inputthe first line was the test Case number T. Then T test cases follow. In each case, the first line was an integer n (1<=n<=8) represents number of the DNA sequences. The following k lines contain the K sequences, one per line. Assuming the length of any sequence are between 1 and 5.OutputFor each test case, print a line containing the length O f The shortest sequence that can is made from these sequences. Sample Input
14ACGTATGCCGTTCAGT
Sample Output
8
Authorllsourcehdu 2006-12 Programming Contest
Search using DFS, but limit recursion depth.
Gradually deepen the search depth until you find the answer.
In the main function, limit the depth of the search, and if there is no solution, deepen the depth of 1 layers
Strong pruning: In the recursive function, the worst case is calculated first, and the length of the supplement is also required:
Sum of lengths for each DNA sequence that has not yet been matched.
If you now search for depth +sum> a limited search depth, return
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Charf[4]={'A','T','G','C'};intFlag,i,t,n,maxlen;intcnt[ -];Charstr[Ten][Ten];voidDfsintLenintcnt[]) { if(Flag | | len>maxlen)return; intsum=0; for(intI=0; i<n;i++)//key: ida* (iterative deepening search) { intL=strlen (Str[i]); Sum=max (sum,l-Cnt[i]); } if(Sum+len>maxlen)return; if(sum==0) {flag=1;return;} for(intI=0;i<4; i++) { Charx=F[i]; intnext[ -]; inttflag=0; for(intj=0; j<n;j++) if(str[j][cnt[j]]==x) {Next[j]=cnt[j]+1; Tflag=1; } Elsenext[j]=Cnt[j]; if(Tflag) DFS (len+1, next);//updated to describe the valid } return;}intMain () {scanf ("%d",&t); for(;t>0; t--) {scanf ("%d",&N); MaxLen=0; for(i=0; i<n;i++) {scanf ("%s", Str[i]); intL=strlen (Str[i]); MaxLen=Max (maxlen,l); } Flag=0; memset (CNT,0,sizeof(CNT)); for(i=0;i< +; i++) {DFS (0, CNT); if(flag) Break; MaxLen++; } printf ("%d\n", MaxLen); } return 0;}
HDU 1560 DNA sequence (iterative deepening search)