/*
找到状态方程:
设 f[i][j]为从第一个序列中选前i个,第二个序列中选j个的权值...
则:
f[i][0] = sum;
f[0][i] = sum;
f[i][j]= max( f[i-1][j-]+p[i-1][j-1]; f[i-1][j]+p[i-1][4]; f[i][j-1]+p[4][j-1] )
*/
#include
#include
int power[5][5]={
{5, -1, -2, -1, -3},
{-1, 5, -2, -3, -4},
{-2, -3, 5, -2, -2},
{-1, -2, -2, 5, -1},
{-3, -4, -2, -1, 0}
};
int f[101][101], s1[101], s2[101];
int N, l1, l2, i, j, sum;
char temp;
int max(int a, int b, int c) {
int tmp=(a>=b)?a:b;
return tmp>=c?tmp:c; // 天哪, 竟然是这种错误:把tmp 和 temp 混淆了..晕
}
void read() {
scanf("%d ", &l1);// 千万要记住加空格,可以把数据先放到记事本里面看一下,空格
for( i=0; i
switch(temp) {
case 'A':
s1[i]=0; break;
case 'C':
s1[i]=1; break;
case 'G':
s1[i]=2; break;
default:
s1[i]=3;
}
}
scanf("%d ", &l2);
for( i=0; i
switch(temp) {
case 'A':
s2[i]=0; break;
case 'C':
s2[i]=1; break;
case 'G':
s2[i]=2; break;
default:
s2[i]=3;
}
}
}
int main() {
// freopen("D://in.txt", "r", stdin);
scanf("%d", &N);
while(N--) {
// read :
read();
// init :
memset(f, 0, sizeof(f) );
sum=0;
for( i=1; i<=l1; i++) {
sum += power[ s1[i-1] ][4];
f[i][0]=sum;
}
sum=0;
for( i=1; i<=l2; i++) {
sum += power[ s2[i-1] ][4];
f[0][i]=sum;
}
// dp
for( i=1; i<=l1; i++) {
for( j=1; j<=l2; j++) {
int tmp1=f[i-1][j-1]+power[s1[i-1]][s2[j-1]];
int tmp2=f[i][j-1] +power[4][s2[j-1]];
int tmp3=f[i-1][j] +power[s1[i-1]][4];
f[i][j]=max(tmp1, tmp2, tmp3);
}
}
// result
printf("%d/n", f[l1][l2] );
}
return 0;
}