Backtracking algorithm: rat in maze
Sept. 10, 2015
Study again the back tracking algorithm using recursive solution, rat in maze, a classical problem. Made a few of mistakes through the practice, one is how to use two dimension array, another one is that "not all return path returns value", not so confident that "return false" at the end of function.
重温二年前做过的算法题, Rat in Maze, 为自己惭愧! 二年前的练习, 没有任何的参考网页信息, 也没有算法讨论, 尝试改进. 感觉到自己的差距, 这次练习, 着重强调把算法能背出来. 一步一步写出来, 发现几个错误. 二维数组不熟悉, 耽误了十几分钟; 另外, 就是, "return false" 在递归函数最后一句, 先是忘了. 总之, 这个经典题目, 十分钟写不出来; 需要二个数组, 边界条件检测, 一点印象没有.
Here are my favorite blogs about this problem:
1. http://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/
2. http://algorithms.tutorialhorizon.com/backtracking-rat-in-a-maze-puzzle/
3. https://www.cs.bu.edu/teaching/alg/maze/
Julia's C# pratice:
https://github.com/jianminchen/AlgorithmsPractice/blob/master/RatInAMaze_BackTracking.cs
And then, try to find more discussion about this problem, came cross blogs to challenge my analysis skills. 搜一下Google, 找到一个很有深度的网页, 看了以后, 体验一下代码, 感觉比自己的水平高了几个档次.
http://blogs.msdn.com/b/mattwar/archive/2005/02/03/366498.aspx
http://blogs.msdn.com/b/mattwar/archive/2005/02/11/371274.aspx
More code to read and then play:
http://www.evercrest.com/ext/CheeseAppropriator.cs
and C# practice:
https://github.com/jianminchen/AlgorithmsPractice/blob/master/MousingAround.cs
Backtracking algorithm: rat in maze的更多相关文章
- 理解Backtracking
Backtracking is an algorithm for finding all solutions by exploring all potential candidates. If the ...
- Jeff Somers's N Queens Solutions 最快的n皇后算法
/* Jeff Somers * * Copyright (c) 2002 * * jsomers@alumni.williams.edu * or * allagash98@yahoo.com * ...
- dataStructure@ Check whether a given graph is Bipartite or not
Check whether a given graph is Bipartite or not A Bipartite Graph is a graph whose vertices can be d ...
- 【数据结构】10分钟教你用栈求解迷宫老鼠问题超详细教程附C++源代码
问题描述 给定一张迷宫地图和一个迷宫入口,然后进入迷宫探索找到一个出口.如下图所示: 该图是一个矩形区域,有一个入口和出口.迷宫内部包含不能穿越的墙壁或者障碍物.这些障碍物沿着行和列放置,与迷宫的边界 ...
- Leetcode——回溯法常考算法整理
Leetcode--回溯法常考算法整理 Preface Leetcode--回溯法常考算法整理 Definition Why & When to Use Backtrakcing How to ...
- BFS与DFS常考算法整理
BFS与DFS常考算法整理 Preface BFS(Breath-First Search,广度优先搜索)与DFS(Depth-First Search,深度优先搜索)是两种针对树与图数据结构的遍历或 ...
- DFS、BFS和Backtracking模板
区别与联系 区别 DFS多用于连通性问题因为其运行思想与人脑的思维很相似,故解决连通性问题更自然,采用递归,编写简便(但我个人不这样觉得...) DFS的常数时间开销会较少.所以对于一些能用DFS就能 ...
- (期望)A Dangerous Maze(Light OJ 1027)
http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...
- 维特比算法(Viterbi Algorithm)
寻找最可能的隐藏状态序列(Finding most probable sequence of hidden states) 对于一个特殊的隐马尔科夫模型(HMM)及一个相应的观察序列,我们常常希望 ...
随机推荐
- ASP.NET Core 1.0中实现文件上传的两种方式(提交表单和采用AJAX)
Bipin Joshi (http://www.binaryintellect.net/articles/f1cee257-378a-42c1-9f2f-075a3aed1d98.aspx) Uplo ...
- 使用UICollectionView实现首页的滚动效果
实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...
- Kafka 如何读取offset topic内容 (__consumer_offsets)
众所周知,由于Zookeeper并不适合大批量的频繁写入操作,新版Kafka已推荐将consumer的位移信息保存在Kafka内部的topic中,即__consumer_offsets topic,并 ...
- java环境搭建和写出一个Helloworld
一.安装环境和配置环境变量(必要环节) 安装java并配置环境变量 :在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击 ...
- IT基础架构规划方案一(网络系统规划)
背景 某集团经过多年的经营,公司业务和规模在不断发展,公司管理层和IT部门也认识到通过信息化手段可以更好地支撑公司业务运营.提高企业生产和管理效率.同时随着新建办公 ...
- MySQL5.7 error log时间显示问题
最近有两三套环境升级到了5.7.16,发现mysql.err中的时间好像有些问题,经查是mysql 5.7后的变更,如下: root@localhost [(none)]>select now( ...
- MYSQL数据库导入出错:#1046 - No database selected
今天遇到的mysql导入Navivat for MySql,总是出错,搞了一会才记起没有创建同名的数据库,然后还是导不进去,原来是要在建立的同名的数据单击右键---->运行Sql文件--> ...
- getting started with transformjs
Introduction In the past two years, more and more friends for mobile web development have used the t ...
- CSS3之盒子模型
display:box 使子元素成行排列如果父级宽度小于子级盒子 不会把超出部分挤出下面 而是直接超出 -box-orient:vertical 使盒子垂直显示 默认水平显示 -box-direct ...
- 学习笔记 HTTP参数污染注入
HTTP参数污染注入源于网站对于提交的相同的参数的不同处理方式导致. 例如: www.XX.com/a?key=ab&key=3 如果服务端返回输入key的值,可能会有 一: ab 二:3 三 ...