poj 1699 Best Sequence(dfs+A(n,n))

网友投稿 741 2022-08-27

poj 1699 Best Sequence(dfs+A(n,n))

poj 1699 Best Sequence(dfs+A(n,n))

题目:​​Sequence

Time Limit: 1000MS

 

Memory Limit: 10000K

Total Submissions: 5467

 

Accepted: 2146

Description

The twenty-first century is a biology-technology developing century. One of the most attractive and challenging tasks is on the gene project, especially on gene sorting program. Recently we know that a gene is made of DNA. The nucleotide bases from which DNA is built are A(adenine), C(cytosine), G(guanine), and T(thymine). Given several segments of a gene, you are asked to make a shortest sequence from them. The sequence should use all the segments, and you cannot flip any of the segments.

For example, given 'TCGG', 'GCAG', 'CCGC', 'GATC' and 'ATCG', you can slide the segments in the following way and get a sequence of length 11. It is the shortest sequence (but may be not the only one).

Input

The first line is an integer T (1 <= T <= 20), which shows the number of the cases. Then T test cases follow. The first line of every test case contains an integer N (1 <= N <= 10), which represents the number of segments. The following N lines express N segments, respectively. Assuming that the length of any segment is between 1 and 20.

Output

For each test case, print a line containing the length of the shortest sequence that can be made from these segments.

Sample Input

15 TCGG GCAG CCGC GATC ATCG

Sample Output

11

分析:已知多个片段个体求极值问题,想到了动态规划。根据题意,两个字符串组合,如s1=“12345”,s2=“345678”新构成的字符串的长度比原来s1的长度要多3,把增加的长度存储在一个二维数组len[1][2]中。这样,对于以字符串si开头的由n个子串组合成的新的字符串的就是si+len(i,j,k,……)[

A(n-1,n-1)种组合情况]。那么怎样模拟这么多的组合情况呢?深度优先搜索。

#include #include #include #include using namespace std;const int INF=0x3f3f3f3f;int getmore(char *s1,char *s2){ int length1=strlen(s1),length2=strlen(s2),i; int m,qi; if(length1>length2)qi=length1-length2; else qi=0; for(;qians)return ; if(count==N && length>t; while(t--){ scanf("%d",&N); ans=INF; memset(length,0,sizeof(length)); memset(used,0,sizeof(used)); memset(len,0,sizeof(len)); for(int i=0;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:hdu 1829 A Bug's Life(带权并查集)
下一篇:小众编程语言同样值得你关注(小众编程语言有哪些)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~