![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
回溯
文章平均质量分 51
liuchenjane
这个作者很懒,什么都没留下…
展开
-
Permutations I , II
Permutations Given a collection of distinct 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],转载 2016-09-20 10:17:42 · 351 阅读 · 0 评论 -
迷宫问题
//迷宫问题:求迷宫中从入口到出口的一条路径 //通常用的是“穷举求解”的方法,即从入口出发,顺某一方向向前探索,若能走通,则继续向前走; //否则沿着原路返回,换一个方向再继续探索,直至所有可能的通路都探索到为止 //为了保证在任何位置上都能沿着原路返回,需要用一个先进先出的堆栈结构来保存从入口到当前位置的路径 /* 可以简单描述如下: do{ 若当前位置可通, 则{原创 2016-11-22 17:20:41 · 409 阅读 · 0 评论 -
139. Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given s = “leetcode”, dict = [“leet”, “co转载 2016-10-20 21:02:10 · 290 阅读 · 0 评论 -
131. Palindrome Partitioning
131. Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s原创 2016-10-20 16:40:22 · 238 阅读 · 0 评论 -
Path Sum I,II
112. Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below b转载 2016-10-12 08:56:21 · 276 阅读 · 0 评论 -
回溯法解决0_1背包问题(迭代和递归)
问题:0/1背包问题 例子:weight数组代表物品重量,value数组代表物品价值,M代表背包容量。背包是按单位价值递减的顺序排列的,即value[i]/weight[i]>value[i-1]/weight[i-1]. const int weight[Max]={1,11,21,23,33,43,45,55};const int value[Max]={11,21,31,33,43,53原创 2016-09-13 21:47:13 · 8869 阅读 · 2 评论 -
N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. n-Queues II 比n-Queue I简单了,n-Queue I 稍作修改即可。不用将结果通过Print表达出来,用计数器纪原创 2016-09-15 12:04:10 · 254 阅读 · 0 评论 -
Combination sum I, II,III && Combination
leetcode上遇到了combination sum,combination,permutation;这些排列组合都与回溯法有关, 而且都用递归。 1. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C w转载 2016-09-17 18:20:37 · 321 阅读 · 0 评论 -
401. Binary Watch
401. Binary Watch A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the转载 2016-09-18 18:54:51 · 524 阅读 · 0 评论 -
51. N-Queens
51. N-Queens Question Editorial Solution My Submissions Total Accepted: 62479Total Submissions: 225904Difficulty: Hard The n-queens puzzle is the problem of placing n原创 2016-09-15 10:58:49 · 526 阅读 · 0 评论