-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path50.cpp
More file actions
37 lines (34 loc) · 725 Bytes
/
50.cpp
File metadata and controls
37 lines (34 loc) · 725 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
37
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
bool dicti(string s, vector<string> dict){
for(int i=0;i<dict.size();i++){
if(s==dict[i]){
return true;
}
}
return false;
}
bool sol(string s, vector<string> dict){
int len = s.length();
if(len == 0) return true;
for(int i=1;i<=len;i++){
if(dicti(s.substr(0, i), dict) && sol(s.substr(i, len - i), dict)) return true;
}
return false;
}
int main(){
//word break problem.
string s;
cin>>s;
vector<string> dict;
int n;
cin>>n;
for(int i=0;i<n;i++){
string t;
cin>>t;
dict.push_back(t);
}
cout<<sol(s, dict)<<endl;
return 0;
}