#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[150][105],match[150][105];
char s1[500010],s2[500010];
void Init()
{
match['A']['A']=match['C']['C']=match['G']['G']=match['T']['T']=5;
match['A']['C']=match['C']['A']=match['A']['T']=match['T']['A']=-1;
match[' ']['T']=match['T'][' ']=-1;
match['A']['G']=match['G']['A']=match['C']['T']=match['T']['C']=-2;
match['G']['T']=match['T']['G']=match['G'][' ']=match[' ']['G']=-2;
match['A'][' ']=match[' ']['A']=match['C']['G']=match['G']['C']=-3;
match['C'][' ']=match[' ']['C']=-4;
}
int main()
{
int t,n,m,i,j,k;
while(scanf("%d",&t)!=EOF)
{
Init();
while(t--)
{
scanf("%d",&n);scanf("%s",s1+1);
scanf("%d",&m);scanf("%s",s2+1);
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++) dp[i][0]=dp[i-1][0]+match[s1[i]][' '];
for(i=1;i<=m;i++) dp[0][i]=dp[0][i-1]+match[' '][s2[i]];
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
dp[i][j]=max(dp[i-1][j]+match[s1[i]][' '],dp[i][j-1]+match[' '][s2[j]]);
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+match[s1[i]][s2[j]]);
}
}
printf("%d\n",dp[n][m]);
}
}return 0;
}poj 1080 Human Gene Functions
最新推荐文章于 2021-01-12 21:21:39 发布
本文介绍了一种基于动态规划的DNA序列比对算法,并通过C++代码详细展示了如何实现该算法。该算法通过计算两个DNA序列之间的匹配得分来评估它们的相似度,适用于生物信息学研究中的序列比对任务。
283

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



