forked from debarati-06/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid Paths.cpp
52 lines (49 loc) · 908 Bytes
/
Grid Paths.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
52
#include <bits/stdc++.h>
using namespace std;
int l=1, c=0, a=0;
bool v[49];
string p;
bool vl () {
return ((!v[c-1]) && c%7>0);
}
bool vr () {
return ((!v[c+1]) && c%7<6);
}
bool vu () {
return ((!v[c-7]) && c>6);
}
bool vd () {
return ((!v[c+7]) && c<42);
}
void o (int d);
int r () {
int s = l-1;
if (l==49 || c==42) {
if (c==42 && l==49) {
a++;
}
return 0;
}
if (vl()&&vr()&&(!vd())&&(!vu())) return 0;
if (vd()&&vu()&&(!vl())&&(!vr())) return 0;
if (vd() && (p[s]=='?' || p[s]=='D')) o(7);
if (vl() && (p[s]=='?' || p[s]=='L')) o(-1);
if (vr() && (p[s]=='?' || p[s]=='R')) o(1);
if (vu() && (p[s]=='?' || p[s]=='U')) o(-7);
return 0;
}
void o(int d) {
c += d;
v[c]=!v[c];
l++;
r();
l--;
v[c]=!v[c];
c -= d;
}
int main() {
cin >> p;
v[0]=!v[0];
r();
cout << a;
}