BFS 4

[Java] 이것이 취업을 위한 코딩테스트다 BFS - 미로탈출

import java.util.*; class Node { int x ; int y ; public Node(int x, int y) { this.x = x; this.y = y; } } public class _2MazeEscape { private static int n = 5; private static int m = 6; private static int[][] edges = { {1, 0, 1, 0, 1, 0}, {1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1} }; public static void main(String[] args) { bfs(0, 0); System.out.println(edges[n..

Java/알고리즘 2020.11.12

[python] 이것이 취업을 위한 코딩테스트다 DFS - 음료수 얼려먹기

n, m = 4, 5 edges = [ [0, 0, 1, 1, 0], [0, 0, 0, 1, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0] ] visited = [[[False] * 5] * 4] def dfs(x, y): if x = n or y = m: return False if edges[x][y] == 0: edges[x][y] = 1 dfs(x - 1, y) dfs(x, y - 1) dfs(x + 1, y) dfs(x, y + 1) return True return False cnt = 0 for i in range(n): for j in range(m): if dfs(i, j): cnt += 1 print(cnt) Reference 해당..

Python/알고리즘 2020.11.12

[Java] 이것이 취업을 위한 코딩테스트다 DFS - 음료수 얼려먹기

public class _3frozenDrinks { private static int n = 4; private static int m = 5; private static boolean[][] visited = new boolean[n][m]; private final static int[][] edges = { {0, 0, 1, 1, 0}, {0, 0, 0, 1, 1}, {1, 1, 1, 1, 1}, {0, 0, 0, 0, 0} }; private static int cnt = 0; public static void main(String[] args) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (dfs(i,j)) { cnt++;..

Java/알고리즘 2020.11.12