It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.
* denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.
14 Source: Asia 2001, Taejon (South Korea) |
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
#define bug printf("hihi\n")
#define eps 1e-12
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
#define N 205
int dp[N][N];
int va[1000][1000];
char a[N],b[N];
int lena,lenb;
void inint()
{
va['A']['A']=5;
va['A']['C']=-1;
va['A']['G']=-2;
va['A']['T']=-1;
va['A']['-']=-3;
va['C']['A']=-1;
va['C']['C']=5;
va['C']['G']=-3;
va['C']['T']=-2;
va['C']['-']=-4;
va['G']['A']=-2;
va['G']['C']=-3;
va['G']['G']=5;
va['G']['T']=-2;
va['G']['-']=-2;
va['T']['A']=-1;
va['T']['C']=-2;
va['T']['G']=-2;
va['T']['T']=5;
va['T']['-']=-1;
va['-']['A']=-3;
va['-']['C']=-4;
va['-']['G']=-2;
va['-']['T']=-1;
}
char step[6]={"AGCT-"};
void solve()
{
int i,j;
memset(dp,-INF,sizeof(dp));
dp[0][0]=0;
for(int i=0;i<=lena;i++)
for(int j=0;j<=lenb;j++)
{
if(i==0&&j==0) continue;
if(i&&j) dp[i][j]=dp[i-1][j-1]+va[a[i]][b[j]];
if(i>0) dp[i][j]=max(dp[i][j],dp[i-1][j]+va[a[i]]['-']);
if(j>0) dp[i][j]=max(dp[i][j],dp[i][j-1]+va['-'][b[j]]);
}
}
int main()
{
inint();
int i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&lena,a+1);
scanf("%d%s",&lenb,b+1);
solve();
printf("%d\n",dp[lena][lenb]);
}
return 0;
}
/*
2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
*/