dfs——回溯法求最短路径

该博客介绍了如何运用回溯法(DFS)寻找最短路径。通过一个包含多个操作步骤的广度优先搜索(BFS)实现,包括填充、倒灌、丢弃等操作。代码示例展示了在不同条件下的路径搜索过程。
摘要由CSDN通过智能技术生成
#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){
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值