DP。wa了一下午,原来是把mmax写在外层循环了。最近事情太多了,刷题根本没状态。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <iostream>
using namespace std; #define MAXN 205
#define INF -99999
#define TOKEN '-' char r[MAXN], l[MAXN];
int dp[MAXN][MAXN];
int t, n, rn, ln;
map<char, int> m; int mmap[][] = {
{, -, -, -, -},
{-, , -, -, -},
{-, -, , -, -},
{-, -, -, , -},
{-, -, -, -, }
}; int getmax(int a, int b) {
return a>b ? a:b;
} void init() {
m['A'] = ;
m['C'] = ;
m['G'] = ;
m['T'] = ;
m[TOKEN] = ;
} int main() {
int i, j, k, tmp, mmax;
init(); #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %s", &rn, r);
scanf("%d %s", &ln, l);
dp[rn][ln] = ;
for (i=rn-; i>=; --i) {
dp[i][ln] = dp[i+][ln] + mmap[m[r[i]]][];
}
for (j=ln-; j>=; --j) {
dp[rn][j] = dp[rn][j+] + mmap[][m[l[j]]];
}
for (i=rn-; i>=; --i) {
for (j=ln-; j>=; --j) {
mmax = INF;
if (r[i] == l[j])
mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+][j+]);
else {
mmax = getmax(mmax, mmap[m[r[i]]][]+dp[i+][j]);
mmax = getmax(mmax, mmap[m[l[j]]][]+dp[i][j+]);
mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+][j+]);
}
dp[i][j] = mmax;
}
}
printf("%d\n", dp[][]);
} return ;
}