-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamer08d.cpp
More file actions
59 lines (55 loc) · 1.05 KB
/
samer08d.cpp
File metadata and controls
59 lines (55 loc) · 1.05 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
// Created by rishabhstr ツ
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
const int MX = 1e3;
string a, b;
int lcs[MX][MX];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int k, len_a, len_b;
cin >> k;
while (k != 0) {
memset(lcs, 0, sizeof(lcs));
cin >> a >> b;
len_a = a.length();
len_b = b.length();
for (int i = 0; i <= len_a; ++i) {
for (int j = 0; j <= len_b; ++j) {
if (i == 0 or j == 0)
lcs[i][j] = 0;
else {
if (a[i-1] == b[j-1]) {
lcs[i][j] = lcs[i-1][j-1]+1;
}
else {
if (lcs[i-1][j] >= k) {
lcs[i][j] = lcs[i-1][j];
}
if (lcs[i][j-1] >= k) {
lcs[i][j] = max(lcs[i][j], lcs[i][j-1]);
}
}
}
}
}
cout << lcs[len_a][len_b] << endl;
cin >> k;
}
return 0;
}