1080

/*
DP,应该说还是比较简单的
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef long long LL;
typedef unsigned long long ULL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define FORi(a,b,c) for(int i=(a);i<(b);i+=c)
#define FORj(a,b,c) for(int j=(a);j<(b);j+=c)
#define FORk(a,b,c) for(int k=(a);k<(b);k+=c)
#define FORp(a,b,c) for(int p=(a);p<(b);p+=c)
#define FORii(a,b,c) for(int ii=(a);ii<(b);ii+=c)
#define FORjj(a,b,c) for(int jj=(a);jj<(b);jj+=c)
#define FORkk(a,b,c) for(int kk=(a);kk<(b);kk+=c)

#define FF(i,a)    for(int i=0;i<(a);i++)
#define FFD(i,a)   for(int i=(a)-1;i>=0;i--)

#define Z(a) (a<<1)
#define Y(a) (a>>1)

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 2000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}


// code begin
int cost[5][5] = {
	5,-1,-2,-1,-3,
	-1,5,-3,-2,-4,
	-2,-3,5,-2,-2,
	-1,-2,-2,5,-1,
	-3,-4,-2,-1,0
};

int Ca;
char S[110],T[110];
int ss,ts,as;
int DP[110][110];

int getId(char c)
{
	if(c=='A') return 0;
	if(c=='C') return 1;
	if(c=='G') return 2;
	if(c=='T') return 3;
	return 4;
}

int main()
{
	read;
	write;
	scanf("%d",&Ca);
	while(Ca--)
	{
		scanf("%d %s",&ss,S+1);
		scanf("%d %s",&ts,T+1);
		memset(DP,0,sizeof(DP));
		FORi(1,ss+1,1)
		{
			DP[i][0] = DP[i-1][0]+cost[getId(S[i])][getId('-')];
		}
		FORi(1,ts+1,1)
		{
			DP[0][i] = DP[0][i-1]+cost[getId('-')][getId(T[i])];
		}
		FORi(1,ss+1,1)
		{
			FORj(1,ts+1,1)
			{
				DP[i][j] = MMAX(DP[i-1][j-1]+cost[getId(S[i])][getId(T[j])],DP[i][j-1]+cost[getId('-')][getId(T[j])],DP[i-1][j]+cost[getId(S[i])][getId('-')]);
			}
		}
		printf("%d\n",DP[ss][ts]);
	}
	return 0;
}

posted @ 2011-04-11 20:08  AC2012  阅读(242)  评论(0编辑  收藏  举报