#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define MAX 150
using namespace std;
int A,B,C;
struct P{
int x,y;
int nextx,nexty;
int cz;//操作
int flag;
int _cou;
}d[MAX][MAX];
void bfs()
{
queue<P> que;
que.push(d[0][0]);
int bj = 0;
P b;
while(!que.empty())
{
b = que.front();
que.pop();
if(b.x==C||b.y==C){
bj=1;
break;
}
else
{
//操作1
if(!d[A][b.y].flag){
d[A][b.y].flag = 1;
d[A][b.y].nextx = b.x,d[A][b.y].nexty = b.y;
d[A][b.y].cz = 1;
d[A][b.y]._cou=d[b.x][b.y]._cou+1;
que.push(d[A][b.y]);
}//操作2
if(!d[b.x][B].flag){
dfs——回溯法求最短路径
最新推荐文章于 2022-11-16 16:43:07 发布
该博客介绍了如何运用回溯法(DFS)寻找最短路径。通过一个包含多个操作步骤的广度优先搜索(BFS)实现,包括填充、倒灌、丢弃等操作。代码示例展示了在不同条件下的路径搜索过程。
摘要由CSDN通过智能技术生成