```
bool wordBreak(string s, unordered_set<string>& wordDict) {
vector<int> res(s.length()+1,0);
int SLength=s.length();
res[0]=1;
for(int i=0;i<SLength;i++)
if(res[i]==1)
for(int j=1;j<=SLength-i;j++)
if(wordDict.find(s.substr(i,j))!=wordDict.end())
res[i+j]=1;
return res[SLength]==1?true:false;
}
```