回溯算法和遞歸算法_回溯算法:遞歸和搜索示例說明

回溯算法和遞歸算法

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

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

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

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

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

    邏輯編程語言(例如Icon,Planner和Prolog)在內部使用回溯來生成答案。

示例問題(騎士的旅行問題) (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.

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

騎士走過的路覆蓋了所有牢房 (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格的棋盤。 單元格中的數字表示騎士的移動次數。

騎士之旅的樸素算法 (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/

回溯算法和遞歸算法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390969.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390969.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390969.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C#中的equals()和==

using System;namespace EqualsTest {class EqualsTest{static void Main(string[] args){//值類型int x 1;int y 1;Console.WriteLine(x y);//TrueConsole.WriteLine(x.Equals(y));//True //引用類型A a new A();B b new B();//Console.WriteLine(ab);//報錯…

JPA JoinColumn vs mappedBy

問題&#xff1a;JPA JoinColumn vs mappedBy 兩者的區別是什么呢 Entity public class Company {OneToMany(cascade CascadeType.ALL , fetch FetchType.LAZY)JoinColumn(name "companyIdRef", referencedColumnName "companyId")private List<B…

TP引用樣式表和js文件及驗證碼

TP引用樣式表和js文件及驗證碼 引入樣式表和js文件 <script src"__PUBLIC__/bootstrap/js/jquery-1.11.2.min.js"></script> <script src"__PUBLIC__/bootstrap/js/bootstrap.min.js"></script> <link href"__PUBLIC__/bo…

pytorch深度學習_深度學習和PyTorch的推薦系統實施

pytorch深度學習The recommendation is a simple algorithm that works on the principle of data filtering. The algorithm finds a pattern between two users and recommends or provides additional relevant information to a user in choosing a product or services.該…

什么是JavaScript中的回調函數?

This article gives a brief introduction to the concept and usage of callback functions in the JavaScript programming language.本文簡要介紹了JavaScript編程語言中的回調函數的概念和用法。 函數就是對象 (Functions are Objects) The first thing we need to know i…

Java 集合-集合介紹

2017-10-30 00:01:09 一、Java集合的類關系圖 二、集合類的概述 集合類出現的原因&#xff1a;面向對象語言對事物的體現都是以對象的形式&#xff0c;所以為了方便對多個對象的操作&#xff0c;Java就提供了集合類。數組和集合類同是容器&#xff0c;有什么不同&#xff1a;數…

為什么Java不允許super.super.method();

問題&#xff1a;為什么Java不允許super.super.method(); 我想出了這個問題&#xff0c;認為這個是很好解決的&#xff08;也不是沒有它就不行的&#xff09;如果可以像下面那樣寫的話&#xff1a; Override public String toString() {return super.super.toString(); }我不…

Exchange 2016部署實施案例篇-04.Ex基礎配置篇(下)

上二篇我們對全新部署完成的Exchange Server做了基礎的一些配置&#xff0c;今天繼續基礎配置這個話題。 DAG配置 先決條件 首先在配置DGA之前我們需要確保DAG成員服務器上磁盤的盤符都是一樣的&#xff0c;大小建議最好也相同。 其次我們需要確保有一塊網卡用于數據復制使用&…

數據庫課程設計結論_結論:

數據庫課程設計結論In this article, we will learn about different types[Z Test and t Test] of commonly used Hypothesis Testing.在本文中&#xff0c;我們將學習常用假設檢驗的不同類型[ Z檢驗和t檢驗 ]。 假設是什么&#xff1f; (What is Hypothesis?) This is a St…

JavaScript數據類型:Typeof解釋

typeof is a JavaScript keyword that will return the type of a variable when you call it. You can use this to validate function parameters or check if variables are defined. There are other uses as well.typeof是一個JavaScript關鍵字&#xff0c;當您調用它時將…

asp.net讀取用戶控件,自定義加載用戶控件

1、自定義加載用戶控件 ceshi.aspx頁面 <html><body> <div id"divControls" runat"server"></div> </body></html> ceshi.aspx.cs頁面 System.Web.UI.UserControl newUC (System.Web.UI.UserControl)Page.LoadContro…

配置Java_Home,臨時環境變量信息

一、內容回顧 上一篇博客《Java運行環境的搭建---Windows系統》 我們說到了配置path環境變量的目的在于控制臺可以在任意路徑下都可以找到java的開發工具。 二、配置其他環境變量 1. 原因 為了獲取更大的用戶群體&#xff0c;所以使用java語言開發系統需要兼容不同版本的jdk&a…

網頁縮放與窗口縮放_功能縮放—不同的Scikit-Learn縮放器的效果:深入研究

網頁縮放與窗口縮放內部AI (Inside AI) In supervised machine learning, we calculate the value of the output variable by supplying input variable values to an algorithm. Machine learning algorithm relates the input and output variable with a mathematical func…

在構造器里調用可重寫的方法有什么問題?

問題&#xff1a;在構造器里調用可重寫的方法有什么問題&#xff1f; 我有一個檢票頁面的類通過抽象方法的結果去去設置頁的標題 public abstract class BasicPage extends WebPage {public BasicPage() {add(new Label("title", getTitle()));}protected abstract…

創建hugo博客_如何創建您的第一個Hugo博客:實用指南

創建hugo博客Hugo is a great tool to use if you want to start a blog.如果您想創建博客&#xff0c;Hugo是一個很好的工具。 I use Hugo myself for my blog, flaviocopes.com, and Ive been using it for more than two years. I have a few reasons for loving Hugo.我本…

Python自動化開發01

一、 變量變量命名規則變量名只能是字母、數字或下劃線的任意組合變量名的第一個字符不能是數字以下關鍵字不能聲明為變量名 [and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not,…

記錄關于vs2008 和vs2015 的報錯問題

出現了 VS2008無法創建項目&#xff0c;無法打開項目的情況&#xff0c;提示這個注冊表鍵值有問題 HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSBuild \ ToolsVersions \ 14.0&#xff0c; 但是查看了注冊表沒有這個鍵。費盡辛萬苦&#xff0c;中午在思密達的一個網站上看到…

未越獄設備提取數據_從三星設備中提取健康數據

未越獄設備提取數據Health data is collected every time you have your phone in your pocket. Apple or Android, the phones are equipped with a pedometer that counts your steps. Hence, health data is recorded. This data could be your one free data mart for a si…

怎么樣用System.out.println在控制臺打印出顏色

問題&#xff1a;怎么樣用System.out.println在控制臺打印出顏色 怎么樣才能在控制臺里打印顏色啊&#xff1f;我想要展示一些有顏色的字體&#xff0c;當處理器發送數據和接收數據的時候&#xff0c;也使用不同顏色的字體。 回答一 在這個Java類里面帶有public static 的數…

sql注入語句示例大全_SQL Order By語句:示例語法

sql注入語句示例大全Order By is a SQL command that lets you sort the resulting output from a SQL query.Order By是一個SQL命令&#xff0c;可讓您對SQL查詢的結果輸出進行排序。 訂購依據(ASC&#xff0c;DESC) (Order By (ASC, DESC)) ORDER BY gives us a way to SORT…