图 DFS BFS 回溯
来源:互联网 发布:网络黑市怎么打开 编辑:程序博客网 时间:2024/06/08 20:48
#1 图的遍历
DFS:先序也可后序,就是无法中序。递归,非递归
https://oj.leetcode.com/tag/depth-first-search/
BFS:层序。只能递归。好处是容易找最短路径。
https://oj.leetcode.com/tag/breadth-first-search/
图:因为有环,所以需要判断是否访问过。
https://oj.leetcode.com/tag/graph/
Backtracking:根据条件,提前终止某些分支的遍历。
https://oj.leetcode.com/tag/backtracking/
D1: https://oj.leetcode.com/problems/clone-graph/ (BFS/DFS)
E12:https://oj.leetcode.com/problems/copy-list-with-random-pointer/ (使用map不是最好办法)
D2:https://oj.leetcode.com/problems/word-ladder/ (BFS)
https://oj.leetcode.com/problems/word-ladder-ii/ (BFS + DFS)
D3:https://oj.leetcode.com/problems/word-search/ (DFS backtracking) (重)
D4:https://oj.leetcode.com/problems/word-break/ (DFS + Mem 或者DP)
https://oj.leetcode.com/problems/word-break-ii/ (DFS + Mem)
D8:https://oj.leetcode.com/problems/valid-sudoku/ (三个布尔矩阵)先除3再乘3的方式计算cell
https://oj.leetcode.com/problems/sudoku-solver/ (DFS backtracking)
检测有向图中的环 (DFS + path检测)
http://lintcode.com/en/problem/topological-sorting/ (BFS)
用于查找所有结果模板
public class Solution { public List<List<Integer>> subsets(int[] S) { Arrays.sort(S); List<List<Integer>> result = new ArrayList<List<Integer>>();List<Integer> path = new ArrayList<Integer>(); helper(S, 0, path, result); return result; } private void helper(int[] input, int index, List<Integer> path, List<List<Integer>> result) { result.add(new ArrayList<Integer>(path)); for (int i = index; i < input.length; i++) { path.add(input[i]); helper(input, i + 1, path, result); path.remove(path.size() - 1); } }}
https://leetcode.com/problems/palindrome-partitioning/
https://leetcode.com/problems/restore-ip-addresses/
C12: https://oj.leetcode.com/problems/path-sum-ii/
D5:https://oj.leetcode.com/problems/letter-combinations-of-a-phone-number/ (DFS)
D6:https://oj.leetcode.com/problems/generate-parentheses/ 1子节点: )或( 2生成结果条件:左右括号都是零 3停止条件: 左边剩的多或者左右之一用光
D7:https://oj.leetcode.com/problems/n-queens/ 模板
https://oj.leetcode.com/problems/n-queens-ii/
D9:https://oj.leetcode.com/problems/subsets/ (输入元素不重复)
https://oj.leetcode.com/problems/subsets-ii/ (输入元素重复,结果不允许重复。hashset省事 前后比较最好)
D10:https://oj.leetcode.com/problems/combinations/
https://oj.leetcode.com/problems/combination-sum/ (输入元素不重复 输入元素可以多次使用)
https://oj.leetcode.com/problems/combination-sum-ii/ (输入元素重复 输入元素不可以多次使用)
D11:https://oj.leetcode.com/problems/permutations/ (visited实现)
http://www.lintcode.com/en/problem/permutations/ (swap实现)
https://oj.leetcode.com/problems/permutations-ii/ (hashmap去重省事O(n^n) visited数组去非常重复杂O(n!))
https://oj.leetcode.com/problems/permutation-sequence/ (除(n-1)!, 模(n-1)! 递归)
https://leetcode.com/problems/next-permutation/ (难)
D12:https://oj.leetcode.com/problems/wildcard-matching/ (TODO)
D13:https://oj.leetcode.com/problems/regular-expression-matching/
https://oj.leetcode.com/problems/surrounded-regions/ (非递归BFS/DFS)
- 图 DFS BFS 回溯
- DFS BFS 回溯法
- 回溯,BFS,DFS学习
- poj 3050(dfs+回溯或bfs均可)
- bfs,dfs(回溯路径)倒水
- 如何学习递归,回溯,DFS,BFS.
- 搜索算法科普型入门文章--Bfs,Dfs和回溯
- 递归,回溯,DFS,BFS的理解和模板
- FOJ 1205 小鼠迷宫问题【BFS+dfs回溯查找路径】
- Uva11882 Biggest Number 【dfs回溯+bfs剪枝】【习题7-15】
- 递归,回溯,DFS,BFS的理解和模板
- BFS广度优先搜索 DFS深度优先搜索 回溯算法
- 【图】BFS与DFS
- 【图】BFS和DFS
- 图的dfs、bfs
- 图的遍历:DFS BFS
- 图的BFS与DFS
- 图的创建BFS DFS
- 在排序数组中的出现次数 Count the number of occurrences in a sorted array
- 杨辉三角
- cocos2dx ver3.3 的Sprite3DTest 例子中可以学到什么
- cheap authentic jerseys from china
- [分享]Ubuntu12.04安装基础教程(图文)
- 图 DFS BFS 回溯
- Ubuntu12.04安装Jdk1.7
- cheap china nfl jerseys
- hats and jerseys for cheap
- wholesale jerseys and hats china
- wholesale jerseys cheap china
- www.gobowl2.com/report.html
- 墙内的Linux(Ubuntu)环境下安装Eclipse+Android SDK(ADT)教程
- AutoIT模拟实现一个简单的供销存的程序