社区讨论
50pts求条闭关
P1605迷宫参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @mkqxivu2
- 此快照首次捕获于
- 2026/01/23 21:41 2 个月前
- 此快照最后确认于
- 2026/01/24 14:01 上个月
CPP
#include <bits/stdc++.h>
using namespace std;
int n, m, t;
// vector<vector<int>> a(5,vector<int>(5,0));
typedef pair<int, int> pii;
int sx, sy, fx, fy;
bool mp[10][10];
bool check(int x, int y)
{
return x <= n && y <= m && x > 0 && y > 0 && !mp[x][y];
}
int ans = 0;
// void bfs()
// {
// queue<pii> q;
// q.push({sx, sy});
// while (!q.empty())
// {
// pii nd = q.front();
// if (check(nd.first, nd.second))
// {
// if (nd.first == fx && nd.second == fy)
// {
// ans++;
// }
// else
// {
// q.push({sx + 1, sy});
// q.push({sx - 1, sy});
// q.push({sx, sy + 1});
// q.push({sx, sy - 1});
// }
// }
// q.pop();
// }
// }
void dfs(int x, int y)
{
if (check(x, y))
{
if (x == fx && y == fy)
{
ans++;
return;
}
else
{
mp[x][y] = 1;
dfs(x + 1, y);
dfs(x - 1, y);
dfs(x, y + 1);
dfs(x, y - 1);
}
}
}
int main()
{
cin >> n >> m >> t;
cin >> sx >> sy >> fx >> fy;
for (int i = 0; i < t; i++)
{
int tx, ty;
cin >> tx >> ty;
mp[tx][ty] = 1;
}
dfs(sx,sy);
cout << ans;
}
/*
2 2 1
1 1 2 2
1 2
1
12
01
*/
dfs,谁帮我条一下闭关
回复
共 6 条回复,欢迎继续交流。
正在加载回复...