蒟蒻求助
  • 板块P1605 迷宫
  • 楼主Leasier
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/5/21 19:23
  • 上次更新2023/11/7 02:04:05
查看原帖
蒟蒻求助
201007
Leasier楼主2020/5/21 19:23

各位巨佬,请问我的代码为什么只有 60 分?

代码:

#include <stdio.h>
#include <stdbool.h>

int dx[7] = {0, -1, 0, 0, 1}, dy[7] = {0, 0, -1, 1, 0};
bool mark[7][7], vis[7][7];

int dfs(int x, int y, int fx, int fy){
	if (x == fx && y == fy) return 1;
	int ans = 0;
	for (int i = 1; i <= 4; i++){
		int new_x = x + dx[i], new_y = y + dy[i];
		if (new_x >= 1 && new_x <= fx && new_y >= 1 && new_y <= fy && !mark[new_x][new_y] && !vis[new_x][new_y]){
            vis[new_x][new_y] = true;
			ans += dfs(new_x, new_y, fx, fy);
            vis[new_x][new_y] = false;
		}
	}
	return ans;
}

int main(){
	int n, m, t, sx, sy, fx, fy;
	scanf("%d %d %d %d %d %d %d", &n, &m, &t, &sx, &sy, &fx, &fy);
    for (int i = 1; i <= t; i++){
        int hinder_x, hinder_y;
        scanf("%d %d", &hinder_x, &hinder_y);
        mark[hinder_x][hinder_y] = true;
    }
    vis[sx][sy] = true;
	printf("%d", dfs(sx, sy, fx, fy));
	return 0;
}
2020/5/21 19:23
加载中...