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
| #include <bits/stdc++.h>
using namespace std;
int main() { string s; int n, nn; cin >> s >> nn; n = s.size(); vector<bool> dp(n + 1, false); set<string> ss; for (int i = 0; i < nn; i++) { string t; cin >> t; ss.insert(t); }
dp[0] = true; for (int i = 0; i <= n; i++) { for (int j = i; j > 0; j--) { if (!dp[j - 1]) continue; if (ss.find(s.substr(j - 1, i - j + 1)) != ss.end()) { dp[i] = true; break; } } }
cout << boolalpha << dp[n]; return 0; }
|