-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2041.cpp
More file actions
36 lines (34 loc) · 820 Bytes
/
P2041.cpp
File metadata and controls
36 lines (34 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
int t;
string s1,s2,s3;
signed main()
{
cin>>t;
while(t--)
{
cin>>s1>>s2>>s3;
int m = s1.size(),n = s2.size(),l = s3.size();
if (m + n != l) {
cout << "NO\n";
continue;
}
bool f[1010][1010];
memset(f,false,sizeof f);
f[0][0] = true;
for (int i = 0; i <= m; ++i) {
for (int j = 0; j <= n; ++j) {
int p = i + j - 1;
if (i > 0) {
f[i][j] |= f[i-1][j] && (s1[i-1] == s3[p]);
}
if (j > 0) {
f[i][j] |= f[i][j-1] && (s2[j-1] == s3[p]);
}
}
}
if(f[m][n]) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}