一道洛谷简单搜索题有一个数据没过


#include <bits/stdc++.h>
using namespace std;
int f[7][7];
int n, m, t;
int re;
int turn[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {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;
}

img

附上题目地址


看了半天也不知道怎么回事


 
#include <bits/stdc++.h>
using namespace std;
int f[7][7];
int n, m, t;
int re;
int turn[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
void dfs(int x, int y)
{
    if (f[x][y] == 2)//x y反了
    {
        re++;
        return;
    }
    f[x][y] = 1;//x y
    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[x + turn[i][0]][y + turn[i][1]] != 1)//x y
                    b = 1;
        //递归
        if (b)
        {
            dfs(x + turn[i][0], y + turn[i][1]);
        }
    }
    f[x][y] = 0;//x y
}
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;
}

x y顺序反了