#include<bits/stdc++.h>
using namespace std;
int a[128][128];
void init()
{
memset(a,0,sizeof(a));
a['A']['A']=5;
a['A']['C']=-1;
a['A']['G']=-2;
a['A']['T']=-1;
a['A']['-']=-3;
a['C']['A']=-1;
a['C']['C']=5;
a['C']['G']=-3;
a['C']['T']=-2;
a['C']['-']=-4;
a['G']['A']=-2;
a['G']['C']=-3;
a['G']['G']=5;
a['G']['T']=-2;
a['G']['-']=-2;
a['T']['A']=-1;
a['T']['C']=-2;
a['T']['G']=-2;
a['T']['T']=5;
a['T']['-']=-1;
a['-']['A']=-3;
a['-']['C']=-4;
a['-']['G']=-2;
a['-']['T']=-1;
}
int main()
{
init();
int i,j,len1,len2,_,ans,dp[128][128];
char s1[128],s2[128];
scanf("%d",&_);
while(_--)
{
scanf("%d",&len1);
scanf("%s",s1);
scanf("%d",&len2);
scanf("%s",s2);
memset(dp,0,sizeof(dp));
for(i=0;i<len1;i++)
{
dp[i+1][0]=dp[i][0]+a[s1[i]]['-'];
}
for(j=0;j<len2;j++)
{
dp[0][j+1]=dp[0][j]+a['-'][s2[j]];
}
for(i=1;i<=len1;i++)
for(j=1;j<=len2;j++)
{
dp[i][j]=max(dp[i][j-1]+a['-'][s2[j-1]],dp[i-1][j]+a[s1[i-1]]['-']);
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+a[s1[i-1]][s2[j-1]]);
}
printf("%d\n",dp[len1][len2]);
}
return 0;
}
hdu 1080 Human Gene Functions 线性dp
最新推荐文章于 2019-03-09 21:14:11 发布