-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1625.cpp
51 lines (47 loc) · 1.14 KB
/
1625.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
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const char d[] = {'L', 'R', 'U', 'D'};
string s;
int ans = 0;
bool vis[9][9];
void brute(int x, int y, int k) {
if (vis[x - 1][y] && vis[x + 1][y] && !vis[x][y - 1] && !vis[x][y + 1]) return;
if (!vis[x - 1][y] && !vis[x + 1][y] && vis[x][y - 1] && vis[x][y + 1]) return;
if (x == 7 && y == 1) {
if (k == 48) ++ans;
return;
}
vis[x][y] = true;
if (s[k] == '?') {
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (1 <= nx && nx <= 7 && 1 <= ny && ny <= 7 && !vis[nx][ny]) {
brute(nx, ny, k + 1);
}
}
} else {
for (int i = 0; i < 4; ++i) {
if (s[k] == d[i]) {
int nx = x + dx[i];
int ny = y + dy[i];
if (1 <= nx && nx <= 7 && 1 <= ny && ny <= 7 && !vis[nx][ny]) {
brute(nx, ny, k + 1);
}
break;
}
}
}
vis[x][y] = false;
}
int main() {
cin >> s;
for (int i = 0; i <= 8; ++i) {
vis[0][i] = vis[8][i] = vis[i][0] = vis[i][8] = true;
}
brute(1, 1, 0);
cout << ans << "\n";
return 0;
}