w

https://www.cis.upenn.edu/~matuszek/cit594-2012/Pages/backtracking.html

  1. Starting at Root, your options are A and B. You choose A.
  2. At A, your options are C and D. You choose C.
  3. C is bad. Go back to A.
  4. At A, you have already tried C, and it failed. Try D.
  5. D is bad. Go back to A.
  6. At A, you have no options left to try. Go back to Root.
  7. At Root, you have already tried A. Try B.
  8. At B, your options are E and F. Try E.
  9. 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.的更多相关文章

  1. PHP配置详解

    [PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; This file controls many aspects of ...

  2. 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 ...

  3. Teach Yourself Scheme in Fixnum Days 6 recursion递归

    A procedure body can contain calls to other procedures, not least itself: (define factorial (lambda ...

  4. too much recursion(太多递归)Uncaught RangeError: Maximum call stack size exceeded BootstrapValidator报错

    在BootstrapValidator中已默认遵守Bootstrap规则,form里的每个输入项目必需包含在类为form-group的标签里,否则BootstrapValidator中定义的field ...

  5. 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 ...

  6. Leetcode总结之Backtracking

    本文我们就Leetcode中的一个类型的题目backtracking进行一系列的总结和归纳.backtracking这个方法本质是建立在递归的基础上,不断尝试新的路径,这里关键是每次尝试完以后需要退回 ...

  7. 【LeetCode】Recursion(共11题)

    链接:https://leetcode.com/tag/recursion/ 247 Strobogrammatic Number II (2019年2月22日,谷歌tag) 给了一个 n,给出长度为 ...

  8. 【大爽python算法】递归算法进化之回溯算法(backtracking)

    作者自我介绍:大爽歌, b站小UP主 , python1对1辅导老师, 时常直播编程,直播时免费回答简单问题. 前置知识: 递归算法(recursion algorithm). 我的递归教程: [教程 ...

  9. form表单验证-Javascript

    Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...

随机推荐

  1. Hadoop 集群搭建 mark

    Hadoop 集群搭建 原创 2016-09-24 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 目标 在3台服务器上搭建 Hadoop2.7.3 ...

  2. 在Linux下如何查CC攻击?

    什么是CC攻击?CC攻击就是利用大量代理服务器对目标计算机发起大量连接,导致目标服务器资源枯竭造成拒绝服务.那么如何判断查询CC攻击呢?本文主要介绍了一些Linux下判断CC攻击的命令. AD:201 ...

  3. root-me web server 20-30 writeup

    Remote File Inclusion-远程文件包含 Get the PHP source code. ctrl+u 进行RFI攻击需要同时具备三个条件(被攻击机器): allow_url_fop ...

  4. 数据库设计(五)第一范式(1NF)?

    In our last tutorial we learned and understood how data redundancy or repetition can lead to several ...

  5. 自动化软件部署的shell脚本

    在实际项目中,我们经常用到需要自动化部署软件的情况,这种情况下,我们就不能人为地在命令行下敲击命令了,一切都需要通过shell脚本自动化完成.所谓自动化完成,其实也就是通过写shell程序,模拟人为敲 ...

  6. windows下使用c++调用redis

    不废话,unix下c++调用 redis可以看这个: http://blog.csdn.net/youngqj/article/details/8266177 ==================== ...

  7. 【转】移动App测试中的最佳做法

    一说起软件测试,测试员想到肯定是去检查文件,功能,API,性能并确定软件是否安全,以及关于软件特定部分的其他事项.但是对于移动测试,测试员不得不基于用户移动使用模式考虑移动相关的功能. 本文是基于我的 ...

  8. jQuery特效:图片的轮播

    Flexslider图片轮播.文字图片相结合滑动切换效果 地址:http://www.helloweba.com/view-blog-265.html 示例:http://www.helloweba. ...

  9. js 风格(注意事项)

    类型   • 原始类型:我们可以直接使用值. ο string ο number ο boolean ο null ο undefined var foo = 1, bar = foo; bar = ...

  10. Oracle体系机构

    Oracle 体系结构1.文件:数据库组成和实例文件;2.系统全局区:SGA内存结构,SGA PGA UGA关,也研究SGA和java池,共享池和大部分的池;3.物理进程和线程 server进程 ba ...