Advertisement
Josif_tepe

Untitled

Apr 22nd, 2023
832
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. const int maxn = 1005;
  5. string a, b;
  6. int dp[maxn][maxn][2];
  7.  
  8. int rec(int at_A, int at_B, bool to_uppercase) {
  9.     if(at_B == -1) {
  10.         if(!to_uppercase) {
  11.             if(at_A == -1) {
  12.                 return 1;
  13.             }
  14.             return 0;
  15.         }
  16.         return 1;
  17.     }
  18.     if(at_A == -1) {
  19.         return 0;
  20.     }
  21.     if(dp[at_A][at_B][to_uppercase] != -1) {
  22.         return dp[at_A][at_B][to_uppercase];
  23.     }
  24.    
  25.     int result = 0;
  26.     if(a[at_A] == b[at_B]) {
  27.         result = max(result, rec(at_A - 1, at_B - 1, false));
  28.     }
  29.     if(toupper(a[at_A]) == b[at_B]) {
  30.         result = max(result, rec(at_A - 1, at_B - 1, true));
  31.     }
  32.     if(islower(a[at_A])) {
  33.         result = max(result, rec(at_A - 1, at_B, to_uppercase));
  34.     }
  35.     return dp[at_A][at_B][to_uppercase] = result;
  36. }
  37. int main() {
  38.     ios_base::sync_with_stdio(false);
  39.     int q;
  40.     cin >> q;
  41.    
  42.     while(q--) {
  43.         cin >> a >> b;
  44.         memset(dp, -1, sizeof dp);
  45.         if(rec((int)a.size() - 1, (int)b.size() - 1, true)) {
  46.             cout << "YES" << endl;
  47.         }
  48.         else {
  49.             cout << "NO" << endl;
  50.         }
  51.     }
  52.    
  53.  
  54.     return 0;
  55. }
  56.  
Advertisement
Comments
  • # text 0.22 KB | 0 0
    1. Manufacturer Private Label - Natural Private Label
    2. We are a fully integrated contract manufacturer of vitamins, minerals, supplements, and other nutraceutical products.
    3. Link:-https://www.naturalprivatelabel.com/en/blog-2/
Add Comment
Please, Sign In to add comment
Advertisement