求助!
  • 板块P1605 迷宫
  • 楼主wcx_is_god
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/6/21 20:06
  • 上次更新2024/6/21 22:44:30
查看原帖
求助!
1253413
wcx_is_god楼主2024/6/21 20:06

求助,样例都不对

#include<bits/stdc++.h>
using namespace std;

int n,m,t,sx,sy,fx,fy,ans = 0;
int mx[4] = {0,0,-1,1},my[4] = {-1,1,0,0};
int a[10][10];

void dfs(int x,int y){
	if(x == fx && y == fy){
		ans++;
		return;
	} 
	for(int i = 0; i < 4; i++){
		int xx = x + mx[i];
		int yy = y + my[i];
		if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 0){
			dfs(xx,yy);
		}
	}
}

int main(){
	cin >> n >> m >> t;
	cin >> sx >> sy >> fx >> sy;
	for(int i = 1; i <= t; i++){
		int x,y;
		cin >> x >> y;
		a[x][y] = 1;
	}
	cout << ans;
	return 0;
}

2024/6/21 20:06
加载中...