关于恐怖的DFS(吓死我了)
查看原帖
关于恐怖的DFS(吓死我了)
772815
一咕咕一楼主2024/8/11 11:44

90分求条(测评结果)

#include <bits/stdc++.h>
#define USED(VAL) VAL++, VAL--
#define INF 0x3f3f3f3f
#define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)
#define Endl cout << "\n"
#define endl '\n'

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LD;

const int MaxNum = 100 + 7;

/*The function of the code was {the functions and ideas...}*/

/*Functions...*/
char a[MaxNum][MaxNum];
int vis[MaxNum][MaxNum];
int n, m;
void DFS(int x, int y)
{
    if (x == n && y == m)
        cout << "Yes", exit(0);
    if (x < 1 || x > n || y < 1 || x > m || a[x][y] != '.' || vis[x][y])
        return;
    vis[x][y] = 1;
    DFS(x - 1, y);
    DFS(x + 1, y);
    DFS(x, y - 1);
    DFS(x, y + 1);
}
inline void solve(void)
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    DFS(1, 1);
    cout << "No";
    return;
}
int main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    FastIO;
    int T;
    T = 1;
    while (T--)
        solve();

    return 0;
}
2024/8/11 11:44
加载中...