#include<bits/stdc++.h>
using namespace std;
int n,deep;
char c[10]="ACGT";
struct node
{
char s[10];
int len;
};
node a[10];
int pos[10];
int get_h()
{
int ans=0;
for(int i=1;i<=n;i++)
{
ans=max(ans,a[i].len-pos[i]);
}
return ans;
}
int dfs(int step)
{
if(step+get_h()>deep)
return 0;
if(!get_h())
return 1;
int tem[10];
for(int i=0;i<4;i++)
{
int flag=0;
for(int j=1;j<=n;j++)
tem[j]=pos[j];
for(int j=1;j<=n;j++)
{
if(a[j].s[pos[j]]==c[i])
{
flag=1;
pos[j]++;
}
}
if(flag)
{
if(dfs(step+1))
return 1;
for(int j=1;j<=n;j++)
{
pos[j]=tem[j];
}
}
}
return 0;
}
int main()
{
int t,i,j,maxn;
cin>>t;
while(t--)
{
cin>>n;
maxn=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].s;
a[i].len=strlen(a[i].s);
pos[i]=0;
}
deep=maxn;
while(1)
{
if(dfs(0)) break;
deep++;
}
cout<<deep<<endl;
}
return 0;
}
HDU1560:DNA sequence(IDA星)
最新推荐文章于 2024-08-03 22:30:59 发布
本文介绍了一种基于DNA序列的比对算法实现,通过构建特定的数据结构和采用深度优先搜索策略来寻找最长公共子序列。该算法适用于生物信息学中多个DNA序列之间的相似性比较,以确定它们之间的遗传关系。

13万+

被折叠的 条评论
为什么被折叠?



