fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string a,b,v;
  5. bool dp(int in,int i,int j){
  6. if(in==v.size())return true;
  7. if(i==a.size()&&j==b.size())return false;
  8. bool uso=false;
  9. if(i<a.size()&&v[in]==a[i])uso=dp(in+1,i+1,j);
  10. if(uso)return true;
  11. if(j<b.size()&&v[in]==b[j])uso=dp(in+1,i,j+1);
  12. if(uso)return true;
  13. return false;
  14. }
  15. bool isInterleave(string A, string B, string C) {
  16. a=A;
  17. b=B;
  18. v=C;
  19. return dp(0,0,0);
  20. }
  21.  
  22. int main() {
  23. int t;
  24. cin>>t;
  25. while(t--)
  26. {
  27. string a,b,c;
  28. cin>>a;
  29. cin>>b;
  30. cin>>c;
  31. cout<<isInterleave(a,b,c)<<endl;
  32. }
  33. // your code goes here
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5284KB
stdin
100
XYYY XXYYXY XYYXXXXXYX 
YXXXYYYY XXY YYXYXYYYYXY 
XYXYXYXXY XXY YYXYXYXYYYXY 
YXY XYXYX XXXXYYXY 
XXX XXXXYYXXXY YYXYXXXYXXYYY 
YXYYY YYYYYYXY YXYXYYXXYXYYY 
X YXYXYXYXY YYYXXXYXYX 
XXXYX YYYY XXYYXYYXY 
YYYYYXXYY YXXYYYXXX XXXXYYYXXYXYXYXYXX 
YXXYXX YYYXX YXXYYXXXXYX 
YYXXYX XXXYXXX XXYXXXXXYYXXY 
YYXY XYYYY XYYYXXYXX 
XXXXX YYXYXYX XXYYXXXYXYYX 
YY YXYYXYYXYX XXXXXYXYXXXX 
XYY YXX XYXXXX 
YYXXYXXYYY XYXXYXY YYYXYYXXYXXXXXYXX 
YXXXXXXYX YYXX XYXXYXXXYYXYY 
YYXX XXYXYY XXXYXXXYXX 
XXYYYYX YXYYXYYYX YXYYXYYXYYYYYXXY 
YYXXYYXYXX Y YXXYXXYYYYY 
Y YYXXXXY XXYXXXXX 
XXXXYXX XYXYYYYX XXYXXXYXYYXYYXY 
XXXXXX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