-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1405.cpp
52 lines (46 loc) · 923 Bytes
/
1405.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
//
// Created by kdongha on 2020/02/26.
//
#include <bits/stdc++.h>
using namespace std;
int N;
long double ans;
int dir[4];
bool visited[29][29];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void go(int n, int x, int y, long double p) {
if (n > N) {
return;
} else if (visited[x][y]) {
ans -= p;
return;
} else {
visited[x][y] = true;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
long double np = p * dir[d] / 100;
go(n + 1, nx, ny, np);
}
visited[x][y] = false;
}
}
void solve() {
cin >> N;
for (int d = 0; d < 4; d++) {
cin >> dir[d];
}
ans = 1;
go(0, N, N, 1);
cout.precision(11);
cout.fixed;
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}