DNA sequence

杭电1019

Problem Description

The twenty-first century is a biology-technology developing century. 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). 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 be not the only one.




 


Input
The 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.
 


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


Sample Input
1
4
ACGT
ATGC
CGTT
CAGT
 


Sample Output

8

Code

之前的代码:

#include<iostream>
#include<string>
using namespace std;
void sort(string a[],int m)
{
	for(int i=1;i<m;i++)
	{
		string temp=a[i];
		int minSum=a[i].length();
		for(int j=i+1;j<=m;j++)
			if(a[j].length()<a[i].length())
				minSum=j;
		a[i]=a[minSum];
		a[minSum]=temp;
	}
}
int main()
{
	int n;
	string a[22];
	cin>>n;
	while(n--)
	{
		int m;
		cin>>m;
		int h=m;
		for(int i=1;i<=m;i++)
			cin>>a[i];
		sort(a,m);
		for(int j=1;j<h;)
		{
			int count[25];
			memset(count,0,sizeof(count));
			for(int k=a[j].length()-1;k>=1;k--)
			{
				for(int t=2;t<=h;t++)
				{
					int kk=a[j].length()-k,p=0;
					while(a[j].substr(kk,1)==a[t].substr(p,1))
					{
						count[t]++;
						kk++;
						p++;
					}
				}
			}
			int max=count[2],flag=2;
			for(int q=3;q<=h;q++)
				if(count[q]>max)
				{
					max=count[q];
					flag=q;
				}
			a[1]=a[1]+a[flag].substr(max,a[flag].length()-max);
			for(int we=flag;we<h;we++)
				a[we]=a[we+1];
			h--;
		}
		cout<<a[1].length()<<endl;
	}
	return 0;
}
这个代码还有点问题,以下是之后的代码:
#include<iostream>
#include<string.h>
using namespace std;
 
char seg[11][101];
int n,ans;
int len[11];
int addlen[11][11];
bool used[11];
 
void add(int m,int n){
    int l,i,j,k;
    k=0;
    for(l=1; l<=len[m] && l<=len[n]; l++){ 
        bool sign=true;
        for(i=0,j=len[m]-l; i<l; i++,j++)
            if(seg[m][j]!=seg[n][i]){
                sign=false;
                break;
            }
        if(sign) k=l;
    }
    addlen[m][n]=len[n]-k;
}
 
void dfs(int pre,int length,int sum){
    if(sum>=ans) return;  
    if(length==n){    
        if(sum<ans)
            ans=sum;
        return;
    }
    for(int i=0; i<n; i++){   
        if(used[i]==false){
            used[i]=true;
            dfs(i,length+1,sum+addlen[pre][i]);
            used[i]=false;
        }
    }
}
 
int main(){
    int i,j,t;
    cin>>t;
    while(t--){
        cin>>n;
        for(i=0; i<n; i++){
            cin>>seg[i];
            len[i]=strlen(seg[i]);
        }
        for(i=0; i<n; i++)
            for(j=0; j<n; j++)
                add(i,j);
 
        ans=1000;
        memset(used,false,sizeof(used));
        for(i=0; i<n; i++){ 
            used[i]=true;
            dfs(i,1,len[i]);
            used[i]=false;
        }
        cout<<ans<<endl;
    }
    return 0;
}

GenBank是由美国国家生物技术信息中心(National Center for Biotechnology Information,NCBI)管理的一个全球性的DNA序列数据库。它是现代生物研究中最重要的资源之一。 GenBank数据库收集并保存了来自各种生物体的DNA序列数据。这些数据来源于科学家研究机构提交的研究成果。每个DNA序列都有一个独特的GenBank入口编号,这个编号可以被其他研究者用来查找引用相关的数据。 GenBank的DNA序列条目包含了许多重要的信息。首先是序列本身,这是DNA的碱基排列。这个序列可以通过ATCG这四个字母来表示,分别代表腺嘌呤、胸腺嘧啶、鸟嘌呤胞嘧啶。此外,还有与序列相关的其他信息,如序列长度、注释、特殊特征等。 DNA序列条目中通常会提供有关该序列的相关研究或实验的详细描述。这些描述可能包括实验方法、数据分析结果、结论等。这些信息对于其他研究者来说是非常重要的,因为它们可以了解到相关研究的具体内容结果。 GenBank的DNA序列条目还包含有关DNA样本来源、物种信息、以及提交者的联系方式等。这样,其他研究者可以与相关的实验室或作者联系,以获取更多的数据或进一步合作。 总之,GenBank的DNA序列条目提供了广泛的DNA序列数据相关信息,为生物学遗传学研究提供了重要的资源。通过查阅使用这些数据,研究者们可以更深入地了解基因与生命活动之间的关系,为科学研究的发展做出贡献。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值