日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

回溯算法和递归算法_回溯算法:递归和搜索示例说明

發(fā)布時(shí)間:2023/11/29 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 回溯算法和递归算法_回溯算法:递归和搜索示例说明 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

回溯算法和遞歸算法

Examples where backtracking can be used to solve puzzles or problems include:

回溯可用于解決難題或問題的示例包括:

  • Puzzles such as eight queens puzzle, crosswords, verbal arithmetic, Sudoku [nb 1], and Peg Solitaire.

    諸如八個(gè)皇后難題,填字游戲,口頭算術(shù),數(shù)獨(dú)[nb 1]和釘接龍等難題。
  • Combinatorial optimization problems such as parsing and the knapsack problem.

    組合優(yōu)化問題,例如解析和背包問題。
  • Logic programming languages such as Icon, Planner and Prolog, which use backtracking internally to generate answers.

    邏輯編程語言(例如Icon,Planner和Prolog)在內(nèi)部使用回溯來生成答案。
  • 示例問題(騎士的旅行問題) (Example Problem (The Knight’s tour problem))

    The knight is placed on the first block of an empty board and, moving according to the rules of chess, must visit each square exactly once.

    騎士被放置在一個(gè)空棋盤的第一塊上,并且根據(jù)國際象棋的規(guī)則移動,必須對每個(gè)廣場精確地訪問一次。

    騎士走過的路覆蓋了所有牢房 (Path followed by Knight to cover all the cells)

    Following is chessboard with 8 x 8 cells. Numbers in cells indicate move number of Knight.

    以下是帶有8 x 8格的棋盤。 單元格中的數(shù)字表示騎士的移動次數(shù)。

    騎士之旅的樸素算法 (Naive Algorithm for Knight’s tour)

    The Naive Algorithm is to generate all tours one by one and check if the generated tour satisfies the constraints.

    樸素算法是一一生成所有巡視,并檢查生成的巡視是否滿足約束條件。

    while there are untried tours { generate the next tour if this tour covers all squares { print this path;} }

    騎士之旅的回溯算法 (Backtracking Algorithm for Knight’s tour)

    Following is the Backtracking algorithm for Knight’s tour problem.

    以下是騎士巡回問題的回溯算法。

    If all squares are visited print the solution Elsea) Add one of the next moves to solution vector and recursively check if this move leads to a solution. (A Knight can make maximum eight moves. We choose one of the 8 moves in this step).b) If the move chosen in the above step doesn't lead to a solutionthen remove this move from the solution vector and try other alternative moves.c) If none of the alternatives work then return false (Returning false will remove the previously added item in recursion and if false is returned by the initial call of recursion then "no solution exists" )

    這是給你的視頻說明 (And here's a video explanation for you)

    翻譯自: https://www.freecodecamp.org/news/backtracking-algorithms-recursive-search/

    回溯算法和遞歸算法

    總結(jié)

    以上是生活随笔為你收集整理的回溯算法和递归算法_回溯算法:递归和搜索示例说明的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。