1
1
#include < iostream>
2
- #include < map >
2
+ #include < cmath >
3
3
#include < vector>
4
+ #define MOD 1000000007
4
5
5
6
using namespace std ;
6
7
7
- int cache[100000 ][202 ];
8
+ int xs, ys, xh, yh, n;
9
+ int cache[401 ][401 ][202 ], T;
10
+ int map[401 ][401 ], dir[4 ][2 ] = { 0 , 1 , 0 , -1 , 1 , 0 , -1 , 0 };
8
11
12
+ bool outside (int x, int y)
13
+ {
14
+ return x < 0 || y < 0 || x > 2 * T || y > 2 * T;
15
+ }
16
+
17
+ int dp (int x, int y, int t)
18
+ {
19
+ int & ret = cache[x][y][t];
20
+ if (ret != -1 ) return ret;
21
+ if (t == 0 ) return ret = 0 ;
22
+
23
+ ret = 0 ;
24
+ for (int k = 0 ; k < 4 ; k++)
25
+ {
26
+ int nextx = x + dir[k][0 ], nexty = y + dir[k][1 ];
27
+ if (!outside (nextx, nexty) && !(nextx == xh && nexty == yh))
28
+ ret = (ret + dp (nextx, nexty, t - 1 )) % MOD;
29
+ }
30
+
31
+ return ret;
32
+ }
33
+
34
+ int main ()
35
+ {
36
+ ios::sync_with_stdio (false );
37
+ cin.tie (NULL );
38
+
39
+
40
+ cin >> xs >> ys >> T >> xh >> yh >> n;
41
+
42
+ if (abs (xs - xh) + abs (ys - yh) > T)
43
+ {
44
+ cout << 0 << ' \n ' ;
45
+ return 0 ;
46
+ }
47
+
48
+ xh = xh - xs + T, yh = yh - ys + T;
49
+ for (int i = 0 ; i <= 2 * T; i++)
50
+ for (int j = 0 ; j <= 2 * T; j++)
51
+ for (int k = 0 ; k <= T; k++) cache[i][j][k] = -1 ;
52
+
53
+ for (int i = 0 ; i < n; i++)
54
+ {
55
+ int x, y;
56
+ cin >> x >> y;
57
+
58
+ x = x - xs + T, y = y - ys + T;
59
+ if (!outside (x, y))
60
+ for (int j = 0 ; j <= T; j++) cache[x][y][j] = 0 ;
61
+ }
62
+
63
+ xs = T, ys = T;
64
+ cache[xs][ys][0 ] = 1 ;
65
+
66
+ int ans = 0 ;
67
+ for (int i = 0 ; i <= T; i++) ans = (ans + dp (xh, yh, i)) % MOD;
68
+
69
+ cout << ans << ' \n ' ;
70
+ }
0 commit comments