[백준 1405번] 미친 로봇

2017. 10. 16. 00:10알고리즘/백준

반응형






소스코드


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
#include <iostream>
#include <cstdio>
using namespace std;
 
int v[35][35],n; // pp[0]=동 pp[1]=서 pp[2]=남 pp[3]=북
int dx[4= { 001-1 };
int dy[4= { 1-100 };
double result = 0, pp[4];
 
void dfs(int x, int y, int depth, double curPP) {
    v[x][y] = 1;
    if (depth == n) {
        v[x][y] = 0;
        result += curPP;
        return;
    }
 
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (!v[xx][yy]) {
            dfs(xx, yy, depth + 1, curPP * pp[i]);
            v[xx][yy] = 0;
        }
    }
}
 
int main() {
    cin >> n;
    for (int i = 0; i < 4; i++) {
        cin >> pp[i];
        pp[i] /= 100;
    }
    dfs(151501.0);
    printf("%.10lf\n", result);
    return 0;
}
cs


반응형