#4128. 深搜—路径计数问题——填空

深搜—路径计数问题——填空

起点为(1,1),终点为右下角

#include

using namespace std;

int map1[21][21]; //记录地图

bool vis[21][21]; //记录某一个位置是否走过

int xx[] = {-1,1,0,0}; //x方向偏移量,上下

int yy[] = {0,0,-1,1}; //y方向偏移量,左右

int n,m,ans;

// 深度优先搜索

void dfs({{ input(1) }} /* 填空1:当前搜索点的横纵坐标 */){

    // 到达终点

    if({{ input(2) }} && {{ input(3) }}){ 填空2:到达终点 格式为 ? == ?

        ans++;

        return;

    }

    for(int i = 0; i < 4; i++){

        int nx = x + xx[i];

        int ny = y + yy[i];

        if(nx < 1 || ny < 1 || nx > n || ny > m)

            continue;

        if({{ input(4) }} == true) continue; // 填空4:判断当前坐标已走过

        if({{ input(5) }} == 1) continue; // 填空5:判断是障碍

        vis[nx][ny] = true;

        dfs({{ input(6) }}); // 填空6:递归向下搜索

        {{ input(7) }}; // 填空7:回溯:取消标记

    }

}

int main(){

    cin >> {{ input(8) }} >> {{ input(9) }}; // 填空8,9:读入行列

    for(int i = 1; i <= n; i++){

        for(int j = 1; j <= m; j++){

            cin >> map1[i][j];

        }

    }

    if({{ input(10) }} == 1){ 填空10:什么情况表示没有一条路线

        cout << 0;

    }else{

        vis[1][1] = true;

        dfs(1,1);

        cout << ans << endl;

    }

    return 0;

}