-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1002.cpp
More file actions
42 lines (33 loc) · 782 Bytes
/
P1002.cpp
File metadata and controls
42 lines (33 loc) · 782 Bytes
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
40
41
#include <bits/stdc++.h>
using namespace std;
long long dp[25][25];
bool blocked[25][25];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int bx, by, cx, cy;
cin >> bx >> by >> cx >> cy;
int dx[9] = {0, -1, -1, 1, 1, -2, -2, 2, 2};
int dy[9] = {0, -2, 2, -2, 2, -1, 1, -1, 1};
for (int k = 0; k < 9; k++) {
int nx = cx + dx[k];
int ny = cy + dy[k];
if (nx >= 0 && nx <= bx && ny >= 0 && ny <= by) {
blocked[nx][ny] = true;
}
}
dp[0][0] = 1;
for (int i = 0; i <= bx; i++) {
for (int j = 0; j <= by; j++) {
if (blocked[i][j]) {
dp[i][j] = 0;
continue;
}
if (i == 0 && j == 0) continue;
if (i > 0) dp[i][j] += dp[i - 1][j];
if (j > 0) dp[i][j] += dp[i][j - 1];
}
}
cout << dp[bx][by] << "\n";
return 0;
}