
回溯
文章平均质量分 65
onlyou2030
内心仰望理想的人都在埋头苦干!
展开
-
leetcode 37:Sudoku Solver
题目:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.原创 2015-10-18 16:37:10 · 228 阅读 · 0 评论 -
leetcode 77:Combinations
题目:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3],原创 2015-11-27 22:45:32 · 295 阅读 · 0 评论 -
leetcode 78:Subsets
题目:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2015-11-27 23:08:28 · 305 阅读 · 0 评论 -
回溯与DFS
背景:有时会遇到这样一类题目,它的问题可以分解,但是又不能得出明确的动态规划或是递归解法,此时可以考虑用回溯法解决此类问题。回溯法的优点 在于其程序结构明确,可读性强,易于理解,而且通过对问题的分析可以大大提高运行效率。但是,对于可以得出明显的递推公式迭代求解的问题,还是不要用回溯 法,因为它花费的时间比较长。 回溯法中,首先需要明确下面三个概念:(一)约束函数:约束函原创 2015-10-11 09:45:52 · 1471 阅读 · 0 评论 -
leetcode 47:Permutations II
题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and原创 2015-11-07 16:20:03 · 300 阅读 · 0 评论 -
leetcode 46:Permutations
题目:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].思路:可原创 2015-11-07 15:36:44 · 329 阅读 · 0 评论 -
leetcode 40:Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in th原创 2015-11-04 16:03:04 · 286 阅读 · 0 评论 -
leetcode 39:Combination Sum
题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlim原创 2015-10-18 17:04:36 · 284 阅读 · 0 评论 -
leetcode 79:Word Search(redo)
题目:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v原创 2015-11-29 13:20:27 · 292 阅读 · 0 评论