💡 Learned
- 파이프라인의 최대 개수를 구하려면 맨 윗 행부터 돌려야 최대값을 구할 수 있습니다.
- dfs
📑 Submitted
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int R, C;
static char[][] map;
static int[] dir = { -1, 0, 1 };
static int answer;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
map = new char[R][C];
for (int i = 0; i < R; i++) {
map[i] = br.readLine().toCharArray();
}
for (int i = 0; i < R; i++) {
connect(i, 0);
}
System.out.println(answer);
}
private static boolean connect(int x, int y) {
if (y == C - 1) {
answer++;
return true;
}
for (int d = 0; d < 3; d++) {
int nx = x + dir[d];
int ny = y + 1;
if (nx >= 0 && ny >= 0 && nx < R && ny < C && map[nx][ny] != 'x') {
map[nx][ny] = 'x';
boolean result = connect(nx, ny);
if (result) {
return true;
}
}
}
return false;
}
}