-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1605.cpp
39 lines (38 loc) · 845 Bytes
/
P1605.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
int n, m, t, sx, sy, fx, fy, time_count;
int change_x[] = {-1, 1, 0, 0};
int change_y[] = {0, 0, -1, 1};
bool path[10][10];
void dfs(int x, int y)
{
if (x == fx && y == fy)
{
time_count++;
return;
}
for (int i = 0; i < 4; i++)
{
int x1 = x + change_x[i], y1 = y + change_y[i];
if (x1 > 0 && x1 <= n && y1 > 0 && y1 <= m && !path[x1][y1])
{
path[x1][y1] = true;
dfs(x1, y1);
path[x1][y1] = false;
}
}
}
int main()
{
cin >> n >> m >> t >> sx >> sy >> fx >> fy;
for (int i = 1; i <= t; i++)
{
int temp_x, temp_y;
cin >> temp_x >> temp_y;
path[temp_x][temp_y] = true;
}
path[sx][sy]=true;
dfs(sx, sy);
cout << time_count;
return 0;
}