Skip to content

Commit ede7626

Browse files
committed
[DFS] baekjoon-17070
1 parent f9f3647 commit ede7626

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
| 12 | | [SWEA-5215 햄버거 다이어트](./src/DFS/swea5215) | |
9292
| 13 | | [Baekjoon-3109 빵집](./src/DFS/P3109) | |
9393
| 14 | | [Baekjoon-1987 알파벳](./src/DFS/P1987) | |
94+
| 15 | | [Baekjoon-17070 파이프 옮기기 1](./src/DFS/P17070) | 삼성 A형 기출 |
9495

9596
### BFS
9697

src/DFS/P17070/Main.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package DFS.P17070;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static int N, cnt;
9+
static int[][] map;
10+
static int[][] del = {{0, 1}, {1, 0}, {1, 1}};
11+
final static int R = 0, D = 1, RD = 2;
12+
13+
public static void main(String[] args) throws Exception {
14+
System.setIn(new FileInputStream("src/DFS/P17070/input.txt"));
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
17+
N = Integer.parseInt(br.readLine());
18+
map = new int[N][N];
19+
for (int i = 0; i < N; i++) {
20+
StringTokenizer st = new StringTokenizer(br.readLine());
21+
for (int j = 0; j < N; j++) map[i][j] = Integer.parseInt(st.nextToken());
22+
}
23+
24+
if (map[N-1][N-1] != 1) dfs(0, 1, R);
25+
System.out.println(cnt);
26+
}
27+
28+
static void dfs(int i, int j, int d) {
29+
for (int to_d = 0; to_d < 3; to_d++) {
30+
if ((to_d == R && d == D) || (to_d == D && d == R)) continue;
31+
int to_i = i + del[to_d][0];
32+
int to_j = j + del[to_d][1];
33+
if (!isValidPath(to_i, to_j) || map[to_i][to_j] == 1) continue;
34+
if (to_d == RD && (map[i][j+1] == 1 || map[i+1][j] == 1)) continue;
35+
if (to_i == N-1 && to_j == N-1) { cnt++; continue; }
36+
dfs(to_i, to_j, to_d);
37+
}
38+
}
39+
40+
static boolean isValidPath(int i, int j) {
41+
return 0 <= i && i < N && 0 <= j && j < N;
42+
}
43+
}

src/DFS/P17070/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## [baekjoon-17070] 파이프 옮기기 1
2+
3+
![image](https://user-images.githubusercontent.com/22045163/108448988-0fca8400-72a6-11eb-904c-c68a7abd4ffd.png)
4+
![image](https://user-images.githubusercontent.com/22045163/108449048-2a046200-72a6-11eb-8e37-722b785ab461.png)
5+
![image](https://user-images.githubusercontent.com/22045163/108449069-338dca00-72a6-11eb-8e1c-a529106c9479.png)
6+
7+
![image](https://user-images.githubusercontent.com/22045163/108449098-40aab900-72a6-11eb-95a0-b6910f4dd8e0.png)

src/DFS/P17070/input.txt

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
16
2+
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
3+
0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0
4+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
5+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6+
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
7+
0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0
8+
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
9+
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
10+
0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0
11+
0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0
12+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13+
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
14+
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
15+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
16+
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
17+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
18+
correct: 664
19+
wrong: 562
20+
21+
/*
22+
23+
6
24+
0 0 0 0 0 0
25+
0 0 0 0 0 0
26+
0 0 0 0 1 0
27+
0 0 1 0 0 0
28+
0 0 0 0 0 0
29+
0 0 0 0 1 0
30+
correct: 1
31+
wrong: 0
32+
33+
6
34+
0 0 0 0 0 0
35+
0 0 0 0 0 0
36+
0 0 0 0 1 0
37+
0 0 1 0 0 0
38+
0 0 0 0 0 0
39+
0 0 0 0 0 0
40+
correct: 5
41+
wrong: 4
42+
43+
6
44+
0 0 0 0 0 0
45+
0 0 0 0 0 0
46+
0 0 0 0 1 0
47+
0 0 1 0 0 0
48+
0 0 0 0 0 0
49+
0 0 0 1 0 0
50+
correct: 3
51+
wrong: 2
52+
53+
7
54+
0 0 0 0 0 0 0
55+
0 0 0 0 0 0 0
56+
0 1 0 0 0 1 0
57+
0 0 0 0 0 0 0
58+
1 0 0 0 1 1 0
59+
0 0 0 0 0 0 0
60+
0 1 0 0 0 0 0
61+
correct: 9
62+
wrong: 8
63+
64+
7
65+
0 0 0 0 0 0 0
66+
0 0 0 0 0 0 0
67+
0 0 0 0 0 1 0
68+
0 0 0 0 0 0 0
69+
0 0 0 0 0 0 0
70+
0 0 0 0 0 0 0
71+
0 0 0 0 0 0 0
72+
correct: 53
73+
wrong: 52
74+
75+
16
76+
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
77+
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
78+
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
79+
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
80+
0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0
81+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
82+
0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0
83+
0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0
84+
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
85+
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
86+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