Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string LCstr(std::string &A, std::string &B)
- {
- std::vector<std::vector<int>> DP(A.size() + 1, std::vector<int>(B.size() + 1, 0));
- int pos = 0, mx = 0;
- for(int i = 1; i <= A.size(); i++)
- {
- for(int j = 1; j <= B.size(); j++)
- {
- if(A[i - 1] == B[j - 1])
- {
- DP[i][j] = DP[i - 1][j - 1] + 1;
- if(DP[i][j] > mx)
- {
- mx = DP[i][j];
- pos = i - 1;
- }
- }
- }
- }
- return A.substr(pos - mx + 1, mx);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement