#include <bits/stdc++.h>
using namespace std;
struct node
{
int x, y;
}pp[1010];
int num;
bool mp[15][15],vis[15][15];
int n, m, sx, sy, ex, ey;
void DFS(int x,int y)
{
if(x < 1 || x > n || y < 1 || y > m || mp[x][y] == 1)
return;
if(x == n && y == m)
{
num++;
return;
}
if(vis[x][y] == 0)
{
vis[x][y] = 1;
DFS(x-1,y);
DFS(x+1,y);
DFS(x,y-1);
DFS(x,y+1);
vis[x][y] = 0;
}
}
int main()
{
int k;
cin >> k;
while(k --)
{
num = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cin >> mp[i][j];
}
memset(vis,0,sizeof(vis));
DFS(1,1);
cout << num << endl;
}
return 0;
}
SDUT 1269 走迷宫
最新推荐文章于 2020-10-31 16:08:26 发布