样例过了才35,求调
  • 板块P1238 走迷宫
  • 楼主slezzlf
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/8/2 16:06
  • 上次更新2025/8/2 16:11:12
查看原帖
样例过了才35,求调
1046868
slezzlf楼主2025/8/2 16:06
#include<bits/stdc++.h>
using namespace std;
int a[20][20],n,m,sx,sy,ex,ey,ro,go[5][3]={{0,1},{0,-1},{1,0},{-1,0}};
bool v[20][20];
void dfs(string s,int x,int y){
	if(x<1)return ;
	if(y<1)return ;
	if(x>n)return ;
	if(y>m)return ;
	if(!a[x][y])return ;
	if(v[x][y])return ;
	if(x==ex&&y==ey){
		ro++;
		cout<<s<<"\n";
	}
	v[x][y]=1;
	for(int i=0;i<=3;i++){
		int nx=x+go[i][0],ny=y+go[i][1];
		string s1=s;
		s1+="->(";
		s1+=char(nx+'0');
		s1+=',';
		s1+=char(ny+'0');
		s1+=')';
		dfs(s1,nx,ny); 
	}
	v[x][y]=0;
	
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	cin>>sx>>sy>>ex>>ey;
	string s1;
	s1='(';
	s1+=char(sx+'0'); 
	s1+=',';
	s1+=char(sy+'0');
	s1+=')';
	dfs(s1,sx,sy);
	if(!ro)cout<<-1;
	return 0;
}
2025/8/2 16:06
加载中...