//4_7_15: Human Gene Functions 基因序列匹配 POJ1080 ZOJ1027
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int score[5][5] = {{-1000,-3,-4,-2,-1},{-3,5,-1,-2,-1},
{-4,-1,5,-3,-2},{-2,-2,-3,5,-2},{-1,-1,-2,-2,5}};
int max(int a,int b,int c)
{
int temp = a > b ? a : b;
return temp > c ? temp : c;
}
int main()
{
int i,j,T,a,b,c,len1,len2,s1[105],s2[105],f[105][105];
char str1[105],str2[105];
scanf("%d",&T);
while(T--)
{
scanf("%d%s",&len1,str1);
scanf("%d%s",&len2,str2);
memset(f,0,sizeof(f));
for(i = 0;i < len1;i ++)
{
if(str1[i] == 'A') s1[i] = 1;
else if(str1[i] == 'C') s1[i] = 2;
else if(str1[i] == 'G') s1[i] = 3;
else s1[i] = 4;
}
s1[len1++] = 0;
for(i = 0;i < len2;i ++)
{
if(str2[i] == 'A') s2[i] = 1;
else if(str2[i] == 'C') s2[i] = 2;
else if(str2[i] == 'G') s2[i] = 3;
else s2[i] = 4;
}
s2[len2++] = 0;
for(i = 1;i <= len1;i ++) f[i][0] = f[i - 1][0] + score[0][s1[i - 1]];
for(j = 1;j <= len2;j ++) f[0][j] = f[0][j - 1] + score[0][s2[j - 1]];
for(i = 1;i <= len1;i ++)
for(j = 1;j <= len2;j ++)
{
a = f[i - 1][j] + score[0][s1[i - 1]];
b = f[i][j - 1] + score[0][s2[j - 1]];
c = f[i - 1][j - 1] + score[s1[i - 1]][s2[j - 1]];
f[i][j] = max(a,b,c);
}
printf("%d\n",max(f[len1 - 1][len2],f[len1][len2 - 1],f[len1 - 1][len2 - 1]));
}
return 0;
}
/*测试结果:通过POJ1080 ZOJ1027检测
2
7 AGTGATG
5 GTTAG
14
7 AGCTATT
9 AGCTTTAAA
21
请按任意键继续. . .
*/
POJ1080 ZOJ1027 Human Gene Functions
最新推荐文章于 2019-11-02 11:01:40 发布