zoukankan      html  css  js  c++  java
  • Backtracking is a form of recursion.

    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.

  • 相关阅读:
    asp.net 进行发送邮箱验证
    获取微信签名,并保存在xml文件中
    webform获取微信用户的授权
    [转载]将json字符串转换成json对象
    使用authentication进行身份验证,与Forms表单登陆
    解决在IE下LABEL中IMG图片无法选中RADIO的几个方法
    php网页切图/js切图
    最近新装系统windows8.1+Mac。。。还没装驱动就遇到一堆问题。。。
    百度地图api根据定位获取附近商家(只获取屏幕内)
    ios ZBar扫二维码奇奇怪怪的错误
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6692009.html
Copyright © 2011-2022 走看看