本题源自LeetCode
------------------------------------------------------------------------------
1 双重遍历字符串,判断子串是否在dic他中
2 用一个数组做标记,判断s[0-i]是否可划分为dict中的子串
bool wordBreak(string s, unordered_set<string> &dict) {
int len=s.length();
vector<bool> dp(len+1,false);
dp[0]=true;
for(int i=0;i<len;i++){
for(int j=i;dp[i] && j<len;j++){
if(match(s.substr(i,j-i+1),dict))
dp[j+1]=true;
}
}
return dp[len];
}
bool match(string str,unordered_set<string> &dict){
if(dict.find(str)!=dict.end())
return true;
return false;
}