-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path1080.cpp
More file actions
65 lines (60 loc) · 1.21 KB
/
1080.cpp
File metadata and controls
65 lines (60 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
#define NOTFOUND -99999
using namespace std;
const int simi[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, -10}};
int mem[105][105];
int l1, l2;
string str1, str2;
int charid(char c)
{
if (c == 'A') return 0;
if (c == 'C') return 1;
if (c == 'G') return 2;
if (c == 'T') return 3;
else return 4;
}
int max(int x, int y)
{
if (x>y) return x;
return y;
}
int f(int x, int y)
{
if (x >= l1 && y >= l2) return 0;
if (mem[x][y] != NOTFOUND) return mem[x][y];
int noskip = NOTFOUND;
int skip1 = NOTFOUND;
int skip2 = NOTFOUND;
if (x < l1 && y < l2)
{
noskip = simi[charid(str1[x])][charid(str2[y])]+f(x+1, y+1);
}
if (y < l2)
{
skip1 = simi[4][charid(str2[y])]+f(x, y+1);
}
if (x < l1)
{
skip2 = simi[charid(str1[x])][4]+f(x+1, y);
}
mem[x][y] = max(noskip, max(skip1, skip2));
return mem[x][y];
}
int main()
{
int testcase;
cin>>testcase;
while (testcase > 0)
{
cin>>l1>>str1>>l2>>str2;
testcase--;
for (int i = 0; i <= l1; i++)
for (int j = 0; j <= l2; j++)
{
mem[i][j] = NOTFOUND;
}
cout<<f(0, 0)<<endl;
}
return 0;
}