rt,评测结果,代码如下,望解答
QWQ
#include <bits/stdc++.h>
using namespace std;
int ans[100005][100], k, r, c, o;
int cx[] = {0, -1, 0, 1};
int cy[] = {-1, 0, 1, 0};
bool vis[17][17];
char a[118][87];
void print() {
for (int h = 0; h <= k - 1; h++)
printf("%d %d\n", ans[h][0], ans[h][1]);
printf("%d %d", r, c);
o = 1;
}
void dfs(int x, int y) {
if (x == r && y == c) {
if (k <= 100000)
print();
return;
}
if (x > r || y > c)
return ;
for (int i = 0; i <= 3; i++) {
if (a[x + cx[i]][y + cy[i]] == '.' && vis[x + cx[i]][y + cy[i]] == 0) {
vis[x][y] = 1;
ans[k][0] = x;
ans[k][1] = y;
k++ ;
dfs(x + cx[i], y + cy[i]);
if (o)
return ;
vis[x][y] = 0;
k--;
}
}
}
int main() {
cin >> r >> c;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++)
cin >> a[i][j];
}
dfs(1, 1);
return 0;
}