I used naive recursion because the constraints were small.

My code is:

So x1, y1 indicates the position upto which we have checked the lasers. The function will copy the grid to a1,a2 and a3. In a1, I killed all enemies in upper direction and recursively called the function again. In a2, I killed all the ones in left direction, and in a3, I killed the ones in right direction. Can someone please help! It sucks that I am getting WA.

```
#include<iostream>
#include<vector>
#include<string>
using namespace std;
bool proc(int x1,int y1,vector<string> a,int n,int m);
int main()
{
int t;
cin >> t;
while(t--)
{
int n,m;
cin >> n >> m;
vector<string> a;
a.resize(n);
for(int i = 0;i < n;i++)
cin >> a[i];
bool c = proc(0,0,a,n,m);
if(c == true) cout << "Possible" << endl;
else cout << "Impossible" << endl;
}
return 0;
}
bool proc(int x1, int y1,vector<string> a,int n,int m) {
int x,y;
for(x = x1;x < n;x++)
for(y = y1;y < m;y++)
if(a[x][y] == 'L') goto label1;
if(x == n || y == m)
{
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
if(a[i][j] == 'E') return false;
return true;
}
label1: ;
vector<string> a1;
vector<string> a2;
vector<string> a3;
a1.resize(n);
a2.resize(n);
a3.resize(n);
for(int i = 0;i < n;i++)
a1[i] = a[i];
for(int i = 0;i < n;i++)
a2[i] = a[i];
for(int i = 0;i < n;i++)
a3[i] = a[i];
for(int i = x;i >= 0;i--)
if(a1[i][y] == 'E') a1[i][y] = '.';
a1[x][y] = '.';
bool l = proc(x,y,a1,n,m);
if(l == true) return true;
for(int i = y;i >= 0;i--)
if(a2[x][i] == 'E') a2[x][i] = '.';
a2[x][y] = '.';
bool k = proc(x,y,a2,n,m);
if(k == true) return true;
for(int i = y;i < m;i++)
if(a3[x][i] == 'E') a3[x][i] = '.';
a3[x][y] = '.';
bool d = proc(x,y,a3,n,m);
if(d == true) return true;
return false;
}
```