Update permute
ci/woodpecker/push/test Pipeline was successful Details

This commit is contained in:
Sainnhe Park 2023-02-03 18:07:50 +08:00
parent a40cbdf78e
commit 7d85d34745
7 changed files with 20 additions and 10 deletions

View File

@ -45,6 +45,7 @@
- [切割问题](./split.md)
- [子集问题](./subsets.md)
- [排列问题](./permute.md)
- [棋盘问题](./chess.md)
# STL

View File

@ -1,9 +1,8 @@
# 总结
使用场景:
使用场景:如果解决一个问题需要多个步骤,而每个步骤都在前一步的基础上进行选择,那么就可以用回溯法。
- 如果解决一个问题需要多个步骤,而每个步骤有多个可能的结果,题目又要求我们找出所有可能的结果,那么这个时候可以考虑回溯法。
- 回溯法本质是在一棵树上进行深度优先遍历
回溯法本质是在一棵树上进行深度优先遍历,因此需要设计好这棵树是如何生成的。
算法设计:
@ -57,10 +56,3 @@ void backtrack(NodeState &node, vector<NodeState> &result, int para1, int para2,
- 时间复杂度:最长路径长度 × 搜索树的节点数
- 空间复杂度:一个节点所需要的空间 × 搜索树的节点数
分类:
- 组合问题N 个数里面按一定规则找出 k 个数的集合
- 切割问题:一个字符串按一定规则有几种切割方式
- 子集问题:一个 N 个数的集合里有多少符合条件的子集
- 排列问题N 个数按一定规则全排列,有几种排列方式
- 棋盘问题N 皇后,解数独等等

3
notes/src/chess.md Normal file
View File

@ -0,0 +1,3 @@
# 棋盘问题
棋盘问题N 皇后,解数独等等

View File

@ -1,5 +1,7 @@
# 组合问题
组合问题N 个数里面按一定规则找出 k 个数的集合
## [77. 组合](https://leetcode.cn/problems/combinations/description/)
![combinations](https://paste.sainnhe.dev/Cytj.png)

View File

@ -1,5 +1,7 @@
# 排列问题
排列问题N 个数按一定规则全排列,有几种排列方式
## [46. 全排列](https://leetcode.cn/problems/permutations/)
## [47. 全排列 II](https://leetcode.cn/problems/permutations-ii/)
@ -81,3 +83,9 @@ vector<vector<int>> S0047::permuteUnique(vector<int> &nums) {
return result;
}
```
## [332. 重新安排行程](https://leetcode.cn/problems/reconstruct-itinerary/)
这道题本来是想不到回溯法的,但是如果某道题能够拆分成多个步骤,每个步骤都在前一步的基础上进行选择,那么就可以用回溯法。
![demo](https://paste.sainnhe.dev/ej8H.png)

View File

@ -1,5 +1,7 @@
# 切割问题
切割问题:一个字符串按一定规则有几种切割方式
## [131. 分割回文串](https://leetcode.cn/problems/palindrome-partitioning/)
![](https://paste.sainnhe.dev/FHTE.jpg)

View File

@ -1,5 +1,7 @@
# 子集问题
子集问题:一个 N 个数的集合里有多少符合条件的子集
## [78. 子集](https://leetcode.cn/problems/subsets/)
其实和切割问题非常像。