90求助,第二个测试w了
  • 板块P1605 迷宫
  • 楼主sajdhkja
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/1/16 23:29
  • 上次更新2023/10/28 12:11:43
查看原帖
90求助,第二个测试w了
618195
sajdhkja楼主2022/1/16 23:29
#include <bits/stdc++.h>
using namespace std;
int f[7][7];
int n, m, t;
int re;
int turn[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void dfs(int x, int y)
{
    if (f[y][x] == 2)
    {
        re++;
        return;
    }
    f[y][x] = 1;
    for (int i = 0; i < 4; i++)
    {
        //判
        bool b = 0;
        if (y + turn[i][1] >= 1 && y + turn[i][1] <= n)
            if (x + turn[i][0] >= 1 && x + turn[i][0] <= m)
                if (f[y + turn[i][1]][x + turn[i][0]] != 1)
                    b = 1;
        //递归
        if (b)
        {
            dfs(x + turn[i][0], y + turn[i][1]);
        }
    }
    f[y][x] = 0;//
}
int main()
{
    cin >> n >> m >> t;
    int stx, sty, enx, eny;
    cin >> stx >> sty >> enx >> eny;
    f[enx][eny] = 2;
    for (int i = 0; i < t; i++)
    {
        int tx, ty;
        cin >> tx >> ty;
        f[tx][ty] = 1;
    }
    f[stx][sty] = 1;
    dfs(stx, sty);
    cout << re;
    return 0;
}
2022/1/16 23:29
加载中...