感谢感谢,可能这题专门加了测试点1来卡dfs的
by bluetored @ 2023-04-05 22:00:30
wc!!!感谢大佬!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!orzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorzorz
by Fwio_ @ 2023-04-14 22:13:07
orz
感谢dalao警示
by caizihaolg @ 2023-05-19 17:54:44
orz
本来我用标记作法调了半天没过,用m * n就好了
by ZYK_luogu @ 2023-06-03 17:29:57
@[_JF_](/user/361141) :大佬,没怎么看懂(~~太菜了~~)
能改一下吗
```cpp
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int MAX_N = 10;
const int MAX_M = 10;
int n, m;
int a[MAX_N][MAX_M];
int color[MAX_N][MAX_M] = {0};
int path = MAX_N * MAX_M;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
void dfs(int i, int j, int xue, int step)
{
if (xue <= 0)
return;
if (step >= n * m)
return;
if (step > path)
return;
if (a[i][j] == 3)
{
if (path > step)
{
path = step;
}
return;
}
if (a[i][j] == 4)
xue = 6;
for (int k = 0; k < 4; k++)
{
int tx = i + dx[k];
int ty = j + dy[k];
if (a[tx][ty] != 0)
{
dfs(tx, ty, xue - 1, step + 1);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (a[i][j] == 2)
{
dfs(i, j, 6, 0);
break;
}
}
}
if (path == MAX_N * MAX_M)
{
cout << "-1";
}
else
{
cout << path;
}
return 0;
}
```
by kkksc1223 @ 2023-07-03 22:03:37
@[ZYK_luogu](/user/742157) 可以分享一下吗,用了n*m还是没过
by LLTT @ 2023-07-03 22:21:42