Advertisement
STANAANDREY

getLCSSlen

Sep 10th, 2020
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ///****************
  4. #define NMAX 1001
  5. char a[NMAX], b[NMAX];
  6. int dp[NMAX][NMAX];
  7. int getLCSSlen(char a[], char b[]) {
  8.     int n = strlen(a + 1);
  9.     int m = strlen(b + 1);
  10.     int ans = 0;
  11.     assert(n < NMAX && m < NMAX);
  12.     for (int i = 1; i <= n; i++)
  13.         for (int j = 1; j <= m; j++)
  14.             if (a[i] == b[j]) {
  15.                 dp[i][j] = dp[i - 1][j - 1] + 1;//else =0;
  16.                 ans = max(ans, dp[i][j]);
  17.             }
  18.     return ans;
  19. }
  20.  
  21. int main() {
  22.     cin >> (a + 1) >> (b + 1);
  23.     std::cerr << getLCSSlen(a, b) << '\n';//9
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement