[BOJ] 3109 빵집

Time Lapse :NONE

3109.c

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
#include <stdio.h>
int R, C;
char buf[10000][501];
int visit[10000][500];
int pipe = 0;
int DFS(int y, int x) {
if (y < 0 || x < 0 || y >= R || x >= C) return 0;
if (buf[y][x] == 'x') return 0;
if (visit[y][x]) return 0;
if (x == C - 1) {
buf[y][x] = 'x';
++pipe;
return 1;
}
visit[y][x] = 1;
if (DFS(y - 1, x + 1)) {
buf[y][x] = 'x';
return 1;
}
if (DFS(y, x + 1)) {
buf[y][x] = 'x';
return 1;
}
if (DFS(y + 1, x + 1)) {
buf[y][x] = 'x';
return 1;
}
return 0;
}

int main(void) {
scanf("%d %d", &R, &C);
for (int i = 0; i < R; ++i)
scanf("%s", buf[i]);
for (int i = 0; i < R; ++i) {
DFS(i, 0);
}
printf("%d", pipe);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/3109/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.