Advertisement
SuitNdtie

toi12_key

May 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int n,m;
  4. char strA[1010];
  5. char strB[1010];
  6. char strC[2010];
  7.  
  8. bool dp[1010][1010];
  9. bool check[1010][1010];
  10.  
  11. bool cal(int i,int j){
  12.     if(i == n && j == m){ //use all
  13.         return true;
  14.     }
  15.     if(check[i][j])return dp[i][j];
  16.    
  17.     int idx = i+j;
  18.     check[i][j] = true;
  19.     if(i < n && j < m && strA[i] == strC[idx] && strB[j] == strC[idx]){
  20.         return dp[i][j] = cal(i+1,j) || cal(i,j+1);
  21.     }
  22.     else if(i < n && strA[i] == strC[idx]){
  23.         return dp[i][j] = cal(i+1,j);
  24.     }
  25.     else if(j < m && strB[j] == strC[idx]){
  26.         return dp[i][j] = cal(i,j+1);
  27.     }
  28.     return dp[i][j] = false;
  29. }
  30.  
  31. int main()
  32. {
  33.     scanf(" %s",strA);
  34.     scanf(" %s",strB);
  35.     n = strlen(strA);
  36.     m = strlen(strB);
  37.     int k;
  38.     scanf("%d",&k);
  39.     for(int t = 1 ; t <= k ; t ++){
  40.         scanf(" %s",strC);
  41.         for(int i = 0 ; i < 1010 ; i ++)for(int j = 0 ; j < 1010 ; j ++)check[i][j] = false;
  42.         printf("%s\n",(cal(0,0) ? "Yes" : "No"));
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement