50分求助!!
  • 板块P1605 迷宫
  • 楼主EveningStudy
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/7 13:29
  • 上次更新2023/11/3 05:25:50
查看原帖
50分求助!!
1023751
EveningStudy楼主2023/8/7 13:29
#include <iostream>
using namespace std;

int N, M, T;
int sx, sy, fx, fy;
bool arr[6][6] = {0};
int ans = 0;

void dfs(int x, int y)
{

    if (arr[x][y] == 0)
    {
        return;
    }
    if (x == fx && y == fy)
    {
        ans++;
        return;
    }
    else
    {
        arr[x][y] = 0;
        dfs(x + 1, y);
        dfs(x, y + 1);
        dfs(x - 1, y);
        dfs(x, y - 1);
        arr[x][y] = 1;
    }
}

int main()
{
    cin >> N >> M >> T;
    cin >> sx >> sy >> fx >> fy;
    sx += 1;
    sy += 1;
    fx += 1;
    fy += 1;

    for (int i = 2; i < N + 2; i++)
    {
        for (int j = 2; j < M + 2; j++)
        {
            arr[i][j] = 1;
        }
    }

    for (int i = 0; i < T; i++)
    {
        int x, y;
        cin >> x >> y;
        x += 1;
        y += 1;
        arr[x][y] = 0;
    }

    if (arr[fx][fy] == 0)
    {
        cout << 0;
        return 0;
    }

    dfs(sx, sy);
    cout << ans;

    return 0;
}
2023/8/7 13:29
加载中...