Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 02 January 2023 [20:47]
- */
- #include<bits/stdc++.h>
- using namespace std;
- char a[1005],b[1005],c[2005];
- int dp[1005][1005];
- int main(){
- int q;
- scanf(" %s %s %d",a+1,b+1,&q);
- int lena=strlen(a+1),lenb=strlen(b+1);
- while(q--){
- scanf(" %s",c+1);
- memset(dp,0,sizeof dp);
- dp[0][0] = 1;
- for(int i=0;i<=lena;i++){
- for(int j=0;j<=lenb;j++){
- if(dp[i][j]){
- if(a[i+1]==c[i+j+1]) dp[i+1][j] = 1;
- if(b[j+1]==c[i+j+1]) dp[i][j+1] = 1;
- }
- }
- }
- if(dp[lena][lenb]) printf("Yes\n");
- else printf("No\n");
- }
- return 0;
- }
- /*
- BAB
- AB
- 4
- BAABB
- BABAB
- ABBAB
- BBABA
- */
Advertisement
Add Comment
Please, Sign In to add comment