forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL.cpp
More file actions
32 lines (27 loc) · 593 Bytes
/
L.cpp
File metadata and controls
32 lines (27 loc) · 593 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
#include <bits/stdc++.h>
using namespace std;
char f[5050][5050], isGood[5050];
int main()
{
string s, t;
cin >> s >> t;
int m = s.size(), n = t.size();
if (s[0] != t[0])
{
cout << "No" << endl;
return 0;
}
f[0][0] = 1;
for (int i = 0; i < m; i++)
for (int j = i; j < n; j++)
{
if (f[i][j] && s[i] == t[j])
{
f[i + 1][j + 1] = 1;
if (j + 1 < n && t[j + 1] != t[j])
isGood[i + 1] = 1;
}
else f[i + 1][j + 1] = isGood[i + 1];
}
cout << (f[m][n] ? "Yes" : "No") << endl;
}