P1605 迷宫 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<bits/stdc++.h>
#define x first
#define y second
const int N = 10;
int g[N][N];
int mp[6][6];
bool st[N][N];
using namespace std;
typedef pair<int, int>PII;
int x1, x2, ya, y2;
int n, m, t,ans;
int dx[] = {0,1,0,-1 }, dy[] = {-1,0,1,0};
void dfs(int x, int y)//定义walk;
{
if (x ==x2 && y == y2)//fx表示结束x坐标,fy表示结束y坐标;
{
ans++;//总数增加;
return;//返回,继续搜索;
}
else
{
for (int i = 0; i < 4; i++)//0——3是左,右,下,上四个方向;
{
int tx = x + dx[i], ty = y + dy[i];
if (st[tx][ty] == 0 && mp[tx][ty] == 1)//判断没有走过和没有障碍;
{
st[x][y] = 1;//走过的地方打上标记;
dfs(tx, ty);
st[x][y] = 0;//还原状态;
}
}
}
}
int main()
{
cin >> n >> m >>t;
for (int i = 1; i <=n; i++)
for (int j = 1; j <= m; j++)
mp[i][j] = 1;
cin >> x1 >> ya >> x2 >> y2;
while (t--)
{
int a, b; cin >> a >> b;
mp[a][b] = 0;
}
dfs(x1,ya);
cout << ans << endl;
return 0;
}