Given an m × n (m row, n-column) labyrinth, maze two positions, Gloria would go from one position to another maze, of course, places some space maze, Gloria can pass through in some places obstacles, she must go around, from a position of the maze, and it can only go four adjacent positions, of course, during walking, gloria can not go outside to go to the maze. Headache is, gloria is no sense of direction, and therefore, she was walking, you can not turn a bend too much, otherwise she would faint. We assume two positions are given space, initially, gloria direction faced yet, she can choose any one of four directions of departure, and not turn into one. gloria from one location to another location you went to?
dfs
has a point very pit ranks are reversed
Counting how often each coordinate needs to turn
to turn too much pruning program
or time out
using namespace std;
typedef long long ll;
int m,n;
char s[105][105];
int k,yy,xx,yyy,xxx;
bool vis[105][105];
bool flag;
int ss[105][105];
int dir[4][2]={1,0,-1,0,0,1,0,-1};
void dfs(int x,int y,int sum,int zhuan){
if(sum>ss[x][y])return;
else ss[x][y]=sum;//重要剪枝!!!
if(x<1||x>m||y<1||y>n||sum>k)return;
if(flag==true)return;
if(x==xxx&&y==yyy){
flag=true;
return;
}
for(int i=0;i<4;i++){
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(s[tx][ty]=='.'&&vis[tx][ty]==false){
vis[tx][ty]=true;
if(zhuan==-1)dfs(tx,ty,sum,i);//以下判断是否转弯
else{
if(i<=1){
if(zhuan>=2)dfs(tx,ty,sum+1,i);
else dfs(tx,ty,sum,i);
}
else{
if(zhuan>=2)dfs(tx,ty,sum,i);
else dfs(tx,ty,sum+1,i);
}
}
vis[tx][ty]=false;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
flag=false;
cin>>m>>n;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
vis[i][j]=false;
ss[i][j]=100000;
cin>>s[i][j];
}
}
cin>>k>>yy>>xx>>yyy>>xxx;
dfs(xx,yy,0,-1);
if(flag)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}