-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcs.cpp
More file actions
34 lines (30 loc) · 828 Bytes
/
Copy pathlcs.cpp
File metadata and controls
34 lines (30 loc) · 828 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
#include <iostream>
using namespace std;
const string lcs(const string &str1, const string &str2)
{
size_t size1 = str2.length();
size_t size2 = str2.length();
if (size1 <= 0 || size2 <= 0)
return NULL;
int count[size1+1][size2+1];
for (int i = 0; i <= size1; i++)
count[0[size2-1] = 0;
for (int j = 0; j <= size2; j++)
count[size1 - 1][0] = 0;
for (int i = 0;i < size1; i++)
{
for (int j = 0; j < size2; j++)
{
if (str1[i] == str2[j])
{
count[i + 1][j+1] = count[i][j] + 1;
}else if (count[i][j+1] >= count[i+1][j])
{
count[i +1][j+1] = count[i][j+1];
}else
{
count[i+1][j+1] = count[i+1][j];
}
}
}
}