为什么
  • 板块P1605 迷宫
  • 楼主lihuadai
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/11/19 23:06
  • 上次更新2023/11/20 13:58:54
查看原帖
为什么
746919
lihuadai楼主2023/11/19 23:06
#include <bits/stdc++.h>
using namespace std;

int fx, fy, n, m, ans = 0;
bool g[13][13]; 

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

void dfs(int x, int y, bool a[][13])
{
    if (x == fx && y == fy)
    {
        ans++;
        return; 
    }
        a[x][y] = true;
    

    for (int i = 0; i < 4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx > 0 && nx <= n && ny > 0 && ny <= m && !g[nx][ny] && !a[nx][ny]) 
         dfs(nx, ny, a);
          
    }


    return;
}

int main()
{
    int t, sx, sy, x, y;
    cin >> n >> m >> t;
    cin >> sx >> sy >> fx >> fy;
    bool a[13][13];
    memset(a, false, sizeof(a)); 
    a[sx][sy] = true;

    while (t--)
    {
        cin >> x >> y;
        g[x][y] = true;
    }

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

    return 0;
}

50分为什么?

2023/11/19 23:06
加载中...