题目大意:中文自己看。
思路:每次dfs,定义4个参数,分别是下一个走到的点x,y和走到这个点的方向dirx,diry。
然后每次dfs走到直管的时候方向不变,走到L型管的时候如果走到当前点的方向是向左(向右)那么方向就应该为向上(向下),如果是向上(向下),那么方向就应该为向左(向右)。每次
dfs如果走到当前点就标记退出即可。
其实思路还是挺简单的,就是细节问题有很多地方需要处理,比如点的越界或者st数组的初始化以及回溯,应该做多了就好了吧(wwww卡在回溯卡了n小时)
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int N=100000+10000;
int n ,m,h,p=0;
char s[5][N];
bool st[5][N];
int X,Y;
void dfs(int dirx,int diry,int x,int y)//上一次的方向和现在走到的点
{
if(p)return ;
if(x==4){
if(y==Y&&dirx==1&&diry==0) p=1;
return ;
}
if(x<2||y<1||y>n||x>=4)return ;//走到第一个点或者第4个点
if(st[x][y])return ;//已经走过了
st[x][y]=true;
if(s[x][y]=='I')//为直的
{
dfs(dirx,diry,x+dirx,y+diry);
}
else if(s[x][y]=='L' ){
if(diry==0)//向下或者向上
{
dirx=0,diry=-1;
dfs(dirx,diry,x+dirx,y+diry); //向左
dirx=0,diry=1;
dfs(dirx,diry,x+dirx,y+diry);
//向右
}
else if(dirx==0)//向左或者向右
{
dirx=1,diry=0;
dfs(dirx,diry,x+dirx,y+diry); //向下
dirx=-1,diry=0;
dfs(dirx,diry,x+dirx,y+diry);
//向上
}
}
st[x][y]=false;
}
int main()
{
int t ;
cin>>t;
while(t--)
{
p=0;
cin>>n>>X>>Y;
for(int i =2;i<=4;i++)
for(int j =1;j<=n;j++)
st[i][j]=false;
for(int i=2;i<=3;i++)
cin>>s[i]+1;
dfs(1,0,2,X);
if(p) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}