题目链接:http://poj.org/problem?id=1080
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; int dp[maxn][maxn];
int A[maxn],B[maxn]; int mymap[][] = {
{, , , , , },
{,,-,-,-,- },
{,-,,-,-,- },
{,-,-,,-,- },
{,-,-,-,,- },
{,-,-,-,-, }
}; int tran(char ch){
int ret;
switch(ch){
case 'A' : ret = ; break;
case 'C' : ret = ; break;
case 'G' : ret = ; break;
case 'T' : ret = ; break;
}
return ret;
}
int main()
{
// freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
while(T--){
int lenA,lenB;
char a[maxn];
scanf("%d %s",&lenA,a+);
for(int i=;i<=lenA;i++) A[i] = tran(a[i]); scanf("%d %s",&lenB,a+);
for(int i=;i<=lenB;i++) B[i] = tran(a[i]); dp[][] = ;
for(int i=;i<=lenB;i++)
dp[][i] = dp[][i-] + mymap[][B[i]];
for(int i=;i<=lenA;i++)
dp[i][] = dp[i-][] + mymap[A[i]][]; // 初始化出现了问题,WA了一次。
for(int i=;i<=lenA;i++)
for(int j=;j<=lenB;j++){
if(A[i] == B[j])
dp[i][j] = dp[i-][j-] + mymap[A[i]][B[j]];
else{
int Max = max(dp[i-][j]+mymap[A[i]][],dp[i][j-]+mymap[][B[j]]);
dp[i][j] = max(dp[i-][j-] + mymap[A[i]][B[j]],Max);
}
}
printf("%d\n",dp[lenA][lenB]);
}
}