Advertisement
YEZAELP

TOI12: key

Jul 2nd, 2020
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char ar1[1010],ar2[1010],str[2010];
  5. bool dp[1010][1010];
  6. int main(){
  7.  
  8.     scanf("%s",ar1);
  9.     scanf("%s",ar2);
  10.     int n, n1 = strlen(ar1), n2 = strlen(ar2);
  11.     scanf("%d",&n);
  12.     for(int i=0;i<n;i++){
  13.         scanf("%s",str);
  14.         dp[n1][n2] = true;
  15.         for(int i=n1; i>=0; i--){
  16.             for(int j=n2; j>=0; j--){
  17.                 if(i+j == n1+n2 and (i!=n1 and j!=n2)) dp[i][j] = false;
  18.                 else if(i!=n1 or j!=n2) dp[i][j] = (str[i+j] == ar1[i] and dp[i+1][j]) or
  19.                                 (str[i+j] == ar2[j] and dp[i][j+1]);
  20.             }
  21.         }
  22.         if(dp[0][0]) printf("Yes\n");
  23.         else printf("No\n");
  24.     }
  25.  
  26.     return 0;
  27. }
Advertisement
RAW Paste Data Copied
Advertisement