diff --git a/notes/src/SUMMARY.md b/notes/src/SUMMARY.md index b111590..527c492 100644 --- a/notes/src/SUMMARY.md +++ b/notes/src/SUMMARY.md @@ -150,4 +150,5 @@ - [70. 爬楼梯 (进阶)](./day45/lc70.md) - [322. 零钱兑换](./day45/lc322.md) - [279.完全平方数](./day45/lc279.md) +- [day 46](./day46.md) - [remains](./remains.md) \ No newline at end of file diff --git a/notes/src/day46.md b/notes/src/day46.md new file mode 100644 index 0000000..284ce19 --- /dev/null +++ b/notes/src/day46.md @@ -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 diff --git a/notes/src/day46/lc139.md b/notes/src/day46/lc139.md new file mode 100644 index 0000000..1ba18ce --- /dev/null +++ b/notes/src/day46/lc139.md @@ -0,0 +1,24 @@ +# 139. 单词拆分 + +不会 + +```cpp +class Solution { +public: + bool wordBreak(string s, vector& wordDict) { + // dp[i] -> 长度为i的字符串是否可以拼出来 + // dp[j] = true if dp[j-i] == true and [i:j] in wordDict + unordered_set wordSet(wordDict.begin(),wordDict.end()); + vectordp(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()]; + } +}; +``` \ No newline at end of file