Backtracking is a form of recursion.
w
https://www.cis.upenn.edu/~matuszek/cit594-2012/Pages/backtracking.html

- Starting at Root, your options are A and B. You choose A.
 - At A, your options are C and D. You choose C.
 - C is bad. Go back to A.
 - At A, you have already tried C, and it failed. Try D.
 - D is bad. Go back to A.
 - At A, you have no options left to try. Go back to Root.
 - At Root, you have already tried A. Try B.
 - At B, your options are E and F. Try E.
 - E is good. Congratulations!
 
In this example we drew a picture of a tree. The tree is an abstract model of the possible sequences of choices we could make. There is also a data structure called a tree, but usually we don't have a data structure to tell us what choices we have. (If we do have an actual tree data structure, backtracking on it is called depth-first tree searching.)
Backtracking is a form of recursion.
The usual scenario is that you are faced with a number of options, and you must choose one of these. After you make your choice you will get a new set of options; just what set of options you get depends on what choice you made. This procedure is repeated over and over until you reach a final state. If you made a good sequence of choices, your final state is a goal state; if you didn't, it isn't.
Conceptually, you start at the root of a tree; the tree probably has some good leaves and some bad leaves, though it may be that the leaves are all good or all bad. You want to get to a good leaf. At each node, beginning with the root, you choose one of its children to move to, and you keep this up until you get to a leaf.
Suppose you get to a bad leaf. You can backtrack to continue the search for a good leaf by revoking your most recent choice, and trying out the next option in that set of options. If you run out of options, revoke the choice that got you here, and try another choice at that node. If you end up at the root with no options left, there are no good leaves to be found.
Backtracking is a form of recursion.的更多相关文章
- PHP配置详解
		
[PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; This file controls many aspects of ...
 - leetcode N-Queens/N-Queens II,  backtracking, hdu 2553 count N-Queens, dfs                                                       分类:            leetcode             hdoj             2015-07-09 02:07    102人阅读    评论(0)    收藏
		
for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...
 - Teach Yourself Scheme in Fixnum Days 6  recursion递归
		
A procedure body can contain calls to other procedures, not least itself: (define factorial (lambda ...
 - too much recursion(太多递归)Uncaught RangeError: Maximum call stack size exceeded  BootstrapValidator报错
		
在BootstrapValidator中已默认遵守Bootstrap规则,form里的每个输入项目必需包含在类为form-group的标签里,否则BootstrapValidator中定义的field ...
 - Creating a new dynamic form project, business modeling.
		
The domain logic is like there are a bunch of objects, as well as a lot of configurations, according ...
 - Leetcode总结之Backtracking
		
本文我们就Leetcode中的一个类型的题目backtracking进行一系列的总结和归纳.backtracking这个方法本质是建立在递归的基础上,不断尝试新的路径,这里关键是每次尝试完以后需要退回 ...
 - 【LeetCode】Recursion(共11题)
		
链接:https://leetcode.com/tag/recursion/ 247 Strobogrammatic Number II (2019年2月22日,谷歌tag) 给了一个 n,给出长度为 ...
 - 【大爽python算法】递归算法进化之回溯算法(backtracking)
		
作者自我介绍:大爽歌, b站小UP主 , python1对1辅导老师, 时常直播编程,直播时免费回答简单问题. 前置知识: 递归算法(recursion algorithm). 我的递归教程: [教程 ...
 - form表单验证-Javascript
		
Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...
 
随机推荐
- Hibernate一级缓存和二级缓存具体解释
			
一.一级缓存二级缓存的概念解释 (1)一级缓存就是Session级别的缓存,一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中.假设短时间内这个 session(一定要同一个ses ...
 - PHPCMS模块开发相关文件
			
名称 类型说明 Guestbook 模块后台控制器 index 模块前台控制器 Install 安装文件夹 ├templates ├config.inc.php ├extention.inc.php ...
 - nyoj 742 子串和再续  类似 HDU 1024
			
子串和再续 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 给你一个序列 S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000 ...
 - windows共享文件的方法
			
众所周知,一个宿舍,一个公司处在一个局域网络中,在不能使用外网通信情况下,此时,我们忘带U盘或者硬盘,同学或同事之间需要拷贝资料或者数据,是不是就不能实现了呢?答案是否定的.微软为了解决这种不必要的麻 ...
 - 基于部标Jt/T809协议和Java Netty框架构建Gps位置监控平台
			
现在地方上由于运输车辆的GPS数据都分散在地方上已有的各种企业平台上面,不利于大数据的分析和智能应用,而开发智能的基于大数据的Gps监控平台,往往需要和各种第三方的部标GPS监控平台对接,获取到第三方 ...
 - android怎样写一个自己定义的dialog能够在Title的位置弹出来
			
先上效果图: Title的Layout为: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr ...
 - The Boss on Mars
			
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
 - JAVA图像缩放处理
			
http://www.blogjava.net/kinkding/archive/2009/05/23/277552.html ———————————————————————————————————— ...
 - Asp.Net中使用水晶报表
			
Asp.Net中使用水晶报表(上) 在我们对VS.Net中的水晶报表(Crystal Reports)进行研究之前,我和我朋友对如何将这个复杂的东东加入我们的Web应用有着非常的好奇心.一周以后,在阅 ...
 - C语言编写的PHP框架--yaf入门编程
			
首先--添加dll,修改php.ini--不同的版本,不同的需求 其次,根据教程http://www.laruence.com/manual/tutorial.firstpage.html#tutor ...