Advertisement
Josif_tepe

Untitled

Oct 3rd, 2022
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6. string A, B;
  7. int dp[1005][1005];
  8. int rec(int i, int j) {
  9.     if(i == -1 and j == -1) {
  10.         return 0;
  11.     }
  12.     if(i == -1) {
  13.         return j + 1;
  14.     }
  15.     if(j == -1) {
  16.         return i + 1;
  17.     }
  18.     if(dp[i][j] != -1) {
  19.         return dp[i][j];
  20.     }
  21.     int result = 2e9;
  22.     if(A[i] == B[j]) {
  23.         result = min(result, rec(i - 1, j - 1) + 1);
  24.     }
  25.     result = min(result, rec(i - 1, j) + 1);
  26.     result = min(result, rec(i, j - 1) + 1);
  27.     return dp[i][j] = result;
  28. }
  29.  
  30. int combinations(int i, int j) {
  31.    
  32. }
  33. int main()
  34. {
  35.     cin >> A >> B;
  36.     memset(dp, -1, sizeof dp);
  37.    
  38.     cout << rec((int) A.size() - 1, (int) B.size() - 1) << endl;;
  39.  
  40.     return 0;
  41. }
  42. /*
  43. ABB
  44. BA
  45.  
  46.  **/
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement