- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLCS.cpp
More file actions
Latest commit
12 lines (10 loc) · 366 Bytes
/
Copy pathLCS.cpp
File metadata and controls
12 lines (10 loc) · 366 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
intlcs(string l, string r) {
vector<vector<int>> dp(l.size(), vector<int>(r.size(), 0));
for (int i = 0; i < l.size(); i++)
for (int j = 0; j < r.size(); j++)
if (l[i] == r[j])
dp[i][j] = i > 0 && j > 0 ? dp[i - 1][j - 1] + 1 : 1;
else
dp[i][j] = max(i > 0 ? dp[i - 1][j] : 0, j > 0 ? dp[i][j - 1] : 0);
return dp[l.size() - 1][r.size() - 1];
}