-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ1405.cpp
59 lines (43 loc) · 1.05 KB
/
BOJ1405.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
53
54
55
56
57
58
59
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool visited[50][50];
int N;
double prob[5];
double p10[30];
ll power10(int a) {
return p10[a];
}
double dfs(int x, int y, ll cnt, double carry) {
//printf("x%d y%d\n", x, y);
if (visited[x][y]) return 0;
double ret = 0;
if (cnt == N) {
return ret = (double)carry;
}
visited[x][y] = true;
ret += dfs(x + 1, y, cnt + 1, carry * prob[1]);
ret += dfs(x - 1, y, cnt + 1, carry * prob[2]);
ret += dfs(x, y - 1, cnt + 1, carry * prob[3]);
ret += dfs(x, y + 1, cnt + 1, carry * prob[4]);
visited[x][y] = false;
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin;
//cin.open("input.txt");
cin >> N >> prob[1] >> prob[2]
>> prob[3] >> prob[4];
prob[1] /= 100;
prob[2] /= 100;
prob[3] /= 100;
prob[4] /= 100;
memset(visited, 0, sizeof(visited));
double ans = dfs(20, 20, 0, 1);
printf("%.9lf", ans);
return 0;
}