0
已解决
周琪岳
资深光能
资深光能
TLE90:
#include <iostream>
using namespace std;
int sx, sy, fx, fy;
int vis[10][10], G[10][10];
const int dir[8][2] = {
{-1, 0}, {-1, 1}, {0, 1}, {1, 1},
{1, 0}, {1, -1}, {0, -1}, {-1, -1}
};
int out[10005][3], total;
bool valid(int x, int y) {
if(x >= 1 && x <= 8 && y >= 1 && y <= 8) return true;
return false;
}
void print(int n) {
for(int i=1; i<=n; i++) {
if(i != n)
cout << "(" << out[i][1] << "," << out[i][2] << ")" << "->";
else
cout << "(" << out[i][1] << "," << out[i][2] << ")";
}
cout << endl;
}
void dfs(int x, int y, int num) {
// cout << x << " " << y << endl;
out[num][1] = x;
out[num][2] = y;
if(x == fx && y == fy) {
total ++;
if(total <= 5)
print(num);
}
for(int i=0; i<8; i++) {
int nx = x + dir[i][0], ny = y + dir[i][1];
if(valid(nx, ny) && vis[nx][ny] == 0 && G[nx][ny] == 0) {
vis[nx][ny] = 1;
dfs(nx, ny, num + 1);
vis[nx][ny] = 0;
}
}
}
int main() {
cin >> sx >> sy >> fx >> fy;
for(int i=1; i<=8; i++)
for(int j=1; j<=8; j++)
cin >> G[i][j];
vis[sx][sy] = 1;
dfs(sx, sy, 1);
cout << total;
return 0;
}