1 条题解

  • -1
    @ 2025-7-15 12:23:37

    #include <bits/stdc++.h> #include <vector> using namespace std; long long n; vector<vector<int> > maze; vector<vector<bool> > visited; long long cnt=0; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; void dfs(int x, int y) { if (x == n - 1 && y == n - 1) { cnt++; return; } 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 < n) { if (maze[nx][ny] == 0 && !visited[nx][ny]) { visited[nx][ny] = true;
    dfs(nx, ny);
    visited[nx][ny] = false; } } } }

    int main() { cin >> n; maze.resize(n, vector<int>(n)); visited.resize(n, vector<bool>(n, false)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> maze[i][j]; } } visited[0][0] = true; dfs(0, 0); cout << cnt << endl; return 0; }

    • 1

    信息

    ID
    545
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    295
    已通过
    49
    上传者