Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int n,m;
- char strA[1010];
- char strB[1010];
- char strC[2010];
- bool dp[1010][1010];
- bool check[1010][1010];
- bool cal(int i,int j){
- if(i == n && j == m){ //use all
- return true;
- }
- if(check[i][j])return dp[i][j];
- int idx = i+j;
- check[i][j] = true;
- if(i < n && j < m && strA[i] == strC[idx] && strB[j] == strC[idx]){
- return dp[i][j] = cal(i+1,j) || cal(i,j+1);
- }
- else if(i < n && strA[i] == strC[idx]){
- return dp[i][j] = cal(i+1,j);
- }
- else if(j < m && strB[j] == strC[idx]){
- return dp[i][j] = cal(i,j+1);
- }
- return dp[i][j] = false;
- }
- int main()
- {
- scanf(" %s",strA);
- scanf(" %s",strB);
- n = strlen(strA);
- m = strlen(strB);
- int k;
- scanf("%d",&k);
- for(int t = 1 ; t <= k ; t ++){
- scanf(" %s",strC);
- for(int i = 0 ; i < 1010 ; i ++)for(int j = 0 ; j < 1010 ; j ++)check[i][j] = false;
- printf("%s\n",(cal(0,0) ? "Yes" : "No"));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement