-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 第九章 动态规划part08 | ||
● 139.单词拆分 | ||
● 关于多重背包,你该了解这些! | ||
● 背包问题总结篇! | ||
|
||
详细布置 | ||
|
||
关于 多重背包,力扣上没有相关的题目,所以今天大家的重点就是回顾一波 自己做的背包题目吧。 | ||
|
||
## 139.单词拆分 | ||
视频讲解:https://www.bilibili.com/video/BV1pd4y147Rh | ||
https://programmercarl.com/0139.%E5%8D%95%E8%AF%8D%E6%8B%86%E5%88%86.html | ||
|
||
## 关于多重背包,你该了解这些! | ||
https://programmercarl.com/%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80%E5%A4%9A%E9%87%8D%E8%83%8C%E5%8C%85.html | ||
|
||
## 背包问题总结篇! | ||
https://programmercarl.com/%E8%83%8C%E5%8C%85%E6%80%BB%E7%BB%93%E7%AF%87.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 139. 单词拆分 | ||
|
||
不会 | ||
|
||
```cpp | ||
class Solution { | ||
public: | ||
bool wordBreak(string s, vector<string>& wordDict) { | ||
// dp[i] -> 长度为i的字符串是否可以拼出来 | ||
// dp[j] = true if dp[j-i] == true and [i:j] in wordDict | ||
unordered_set<string> wordSet(wordDict.begin(),wordDict.end()); | ||
vector<bool>dp(s.size()+1,false); | ||
dp[0]=true; | ||
for (int i = 1 ; i<=s.size();i++) { | ||
for (int j = 0; j < i; j ++ ) { | ||
string word = s.substr(j,i-j); | ||
if (dp[j] && wordSet.find(word)!= wordSet.end()) | ||
dp[i] = true; | ||
} | ||
} | ||
return dp[s.size()]; | ||
} | ||
}; | ||
``` |