acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 正经题解|迷宫之最少花费时间

    【算法分析】 dfs,回溯,如果下一个点符合条件则继续递归,直到找到终点。 【参考代码】 【时间复杂度】 O(nm)O(nm)O(nm) 【预计得分】 100pts100pts100pts

    userId_undefined

    AC君

    管理员
    倔强青铜
    265阅读
    0回复
    2点赞
  • 题解!!!!!!!!!!!!!!!!!!

    userId_undefined

    枫原万叶

    倔强青铜
    135阅读
    0回复
    2点赞
  • 学完堆以后的第一件事:

    userId_undefined

    复仇者_帅童

    尊贵铂金
    47阅读
    8回复
    0点赞
  • 题解

    userId_undefined

    准

    倔强青铜
    51阅读
    0回复
    0点赞
  • T-T

    userId_undefined

    juhan214

    倔强青铜
    14阅读
    0回复
    0点赞
  • 题解

    *#include <bits/stdc++.h> using namespace std; const int N = 30; char mp[N][N]; int n, m, ans = 2e9; int sx, sy, ex, ey; int dir[4][2] = {0,1,1,0,0,-1,-1,0}; bool vis[N][N]; bool in(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } void DFS(int x, int y, int sum) { if(x == ex && y == ey) { if(sum < ans) ans = sum; return; } vis[x][y] = true; for(int i = 0; i < 4; i++) { int nx = x + dir[i][0]; int ny = y + dir[i][1]; if(in(nx, ny) && !vis[nx][ny] && mp[nx][ny] != '#') { if(mp[nx][ny] >= '1' && mp[nx][ny] <= '9') DFS(nx, ny, sum + (mp[nx][ny] - '0') + 1); else DFS(nx, ny, sum + 1); } } vis[x][y] = false; } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> mp[i][j]; if(mp[i][j] == 'Z') sx = i, sy = j; if(mp[i][j] == 'W') ex = i, ey = j; } } DFS(sx, sy, 0); if(ans == 2e9) cout << "IMPOSSIBLE"; else cout << ans; return 0; }*

    userId_undefined

    恶龙世纪

    倔强青铜
    8阅读
    0回复
    0点赞
首页