-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaekjoon3109.java
96 lines (71 loc) · 2.04 KB
/
Baekjoon3109.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package algo.Algorithms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/3109
* 백준 3109 빵집
*/
public class Baekjoon3109 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static int R, C;
static char[][] map;
static List<Node> passed = new ArrayList<>();
static boolean visited[][];
static int count = 0;
private static boolean flag = false;
public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
visited = new boolean[R][C];
map = new char[R][C];
for (int i = 0; i < R; i++) {
String str = br.readLine().trim();
for (int j = 0; j < C; j++) {
map[i][j] = str.charAt(j);
}
}
for (int i = 0; i < R; i++) {
flag = false;
Node node = new Node(i, 0);
dfs(node);
}
System.out.println(count);
}
private static void dfs(Node node) {
if (node.y == C - 1) {
count++;
flag = true;
return;
}
for (int i = -1; i < 2; i++) {
int nX = node.x + i;
int nY = node.y + 1;
if (nX < 0 || nX >= R || nY >= C) continue;
if (map[nX][nY] == 'x' || visited[nX][nY]) continue;
visited[nX][nY] = true;
Node nextNode = new Node(nX, nY);
dfs(nextNode);
if(flag) break;
}
}
static class Node {
int x, y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Node{" +
"x=" + x +
", y=" + y +
'}';
}
}
}