-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNA.cpp
More file actions
43 lines (32 loc) · 921 Bytes
/
DNA.cpp
File metadata and controls
43 lines (32 loc) · 921 Bytes
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
// Solution to this: https://www.codechef.com/problems/KGP14B
#include <iostream>
using namespace std;
int main ()
{
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n, m;
cin >> n >> m;
string str1, str2;
cin >> str1 >> str2;
int dp[n+1][m+1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
dp[i][j] = 0;
};
};
int maxel = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (str1[i-1] == str2[j-1]) {
dp[i][j] = dp[i-1][j-1] + 1;
} else {
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
};
maxel = max(maxel, dp[i][j]);
};
};
cout << "Case "<< i+1 << ": " << maxel + (n-maxel) + (m-maxel) << endl;
};
}