深度优先搜索
来源:互联网 发布:mysql insert into 慢 编辑:程序博客网 时间:2024/05/23 11:51
思想
#include <iostream>using namespace std;int sign[10][10];int min = 99;void run(int a[5][4],int x, int y, int p, int q,int step){int next[4][2] ={{0, 1},{1, 0},{0, -1},{-1, 0}};int tx, ty;if(x == p && y == q){if( step < min )min = step;return ;}for (int k = 0; k <= 3; k++ ){tx = x + next[k][0];ty = y + next[k][1];if( tx < 0 || tx > 5 || ty < 0 || ty > 4 )continue;if(a[tx][ty] == 0 && sign[tx][ty] ==0){sign[tx][ty] = 1;run(a,tx, ty, p, q, step+1);sign[tx][ty] = 0;}}return;}int main(){int a[5][4] ={{0, 0, 1, 0},{0, 0, 0, 0},{0, 0, 1, 0},{0, 1, 0, 0},{0, 0, 0, 1}};int step=0;int startx = 0;int starty = 0;int endx = 3;int endy = 2;sign[0][0] = 1;run(a,startx, starty, endx, endy, step);cout << min<<endl;;return 0;}
0 0
- 深度优先搜索
- 深度优先搜索
- 深度优先搜索 DFS
- 深度优先搜索遍历
- 深度优先搜索 DFS
- 深度优先搜索
- 深度优先搜索
- 深度优先搜索算法
- hdoj1015Safecracker(深度优先搜索)
- [AI]深度优先搜索
- 深度优先搜索算法
- DFS 深度优先搜索
- 深度优先搜索
- 深度优先搜索算法
- 图解深度优先搜索
- 深度优先搜索
- 深度优先搜索
- 深度优先搜索算法
- HBase集群+Zookeeper集群安装
- Struts2 与 Spring 的集成
- Unity3d 性能优化遐想 OnBecameVisible/OnBecameInvisible
- 【Java】Java学习进度_W3
- CSS盒模型宽度
- 深度优先搜索
- 百度前端培训 task1 -深入理解line-height
- c++中map的用法
- 杭电ACM 1091:A+B for Input-Output Practice (III)
- evacuate-instance-automatically
- JSP学习笔记-基础知识
- 对 CNN 中 dropout layer 的理解
- MHA 配置文件样本描述
- java多线程、线程池的实现