RE了大佬能帮忙看一下吗
查看原帖
RE了大佬能帮忙看一下吗
1055920
taoqiniu楼主2024/1/1 13:38
#include<bits/stdc++.h>
using namespace std;
int h,w;
char a[1000][1000];
string s="snuke";
int xx[]={1,0,-1,0};
int yy[]={0,1,0,-1};
void dfs(int x,int y,int z){
	if(x==h && y==w){
		cout<<"Yes";
		exit(0);
	}
	for(int i=0;i<4;i++){
		int tx=xx[i]+x;
		int ty=yy[i]+y;
		char t=s[z%5];
		if(tx>=1 && ty>=1 && tx<=h && ty<=w && a[tx][ty]==t){
			dfs(tx,ty,z+1);
		}
	}
}
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
		}
	}
	if(a[1][1]=='s') dfs(1,1,1);
	cout<<"No";
	return 0;
}
2024/1/1 13:38
加载中...