-
Notifications
You must be signed in to change notification settings - Fork 1
/
[백준 알고리즘] 빵집.txt
72 lines (59 loc) · 1.4 KB
/
[백준 알고리즘] 빵집.txt
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
//빵집
//풀이 아이디어
// 티스토리에서 dfs룰 사용한 이유
//한번 찍고 1만 리턴해서 종복을 방지함 나머지 row들에게 기회를 주기위함. 단, 맨위로 가는 것으로 시작한다
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct cell{
int r,c;
int val;
}Cell;
int rdir[3] ={-1,0,1};
int cdir[3] = {1,1,1};
char arr[10001][501];
bool visit[10001][501];
int n,m;
int result = 0;
int dfs(int r, int c){
if(c == m-1){
return 1;
}
else{
for(int i =0;i<3; i++){
int nowR = r + rdir[i];
int nowC = c + cdir[i];
if(0<=nowR && nowR<n && 0<=nowC && nowC<m &&
visit[nowR][nowC] == false && arr[nowR][nowC] =='.'){
visit[nowR][nowC] = true;
int val = dfs(nowR, nowC);
if(val) return val;
}
}
}
return 0;
}
int main(){
scanf("%d %d", &n, &m);
for(int i =0;i<n; i++){
for(int j =0;j<n; j++){
visit[i][j] = false;
}
}
for(int i =0;i<n; i++){
string temp;
cin >> temp;
for(int j =0;j<m; j++){
arr[i][j] = temp[j];
}
}
for(int i =0;i<n; i++){
result += dfs(i,0);
}
printf("%d", result);
return 0;
}