全部超时但是不知道哪里错了啊【大哭】
查看原帖
全部超时但是不知道哪里错了啊【大哭】
427617
蒟蒻珂学家楼主2021/10/5 09:54

如上。

我和题解区一篇题解十分相似,但是核对之后它的AC了,但是我的TLEqwq

劳烦各路神仙大佬帮忙看看俺的代码吧。

#include <iostream>
#include <string>
using namespace std;
int n, m, t, map[7][7];//map:-1 —— 障碍物。0 —— 畅通
int vis[7][7], sx, sy, ans = 0;//vis:1 —— 走过。0 —— 畅通
struct node{
    int x, y;
};
node q, z;
int wx[4] = {0, 0, -1, 1};
int wy[4] = {-1, 1, 0, 0};
void dfs(node now){
    if(now.x == z.x && now.y == z.y)
    {
        ans++;
        return;
    }
    for(int i = 0; i < 4; i++){
        if(vis[now.x + wx[i]][now.y + wy[i]] == 0 && map[now.x + wx[i]][now.y + wy[i]] == 0){
            vis[now.x][now.y] = 1;
            dfs((node){now.x + wx[i], now.y + wy[i]});
            vis[now.x][now.y] = 0;
        }
    }
}
int main(){
    cin >> q.x >> q.y;
    cin >> t;
    cin >> q.x >> q.y >> z.x >> z.y;
    for(int i = 1; i <= t; i++){
        cin >> sx >> sy;
        map[sx][sy] = -1;
    }dfs(q);
    cout << ans << endl;
    return 0;
}
2021/10/5 09:54
加载中...