/*
还是和决策树一样,从s的第0个位置开始遍历,
然后只要word是s的子串,那么则置为true,而且要注意边界条件
*/
class Solution {
public:
bool wordBreak(string s, vector<string>& wordDict) {
vector<bool> dp(s.length()+1,false);
dp[0]=true;
for(int i=0;i<s.length();i++){
for(auto word : wordDict){
if(dp[i]&&(i+word.length()<=s.length())&&word==s.substr(i,word.length())){
dp[i+word.length()]=dp[i];
}
}
}
return dp[s.length()];
}
};