yu-heejin / coding-test

백준, 프로그래머스 코딩 테스트 💻
https://www.mycompiler.io/ko/new/java
1 stars 0 forks source link

[백준] 오목 #25

Closed yu-heejin closed 2 months ago

yu-heejin commented 7 months ago

https://www.acmicpc.net/problem/2615

yu-heejin commented 7 months ago

import java.io.; import java.util.;

public class Main { static int[][] board; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    board = new int[19][19];
    String[] input;
    for (int i = 0; i < 19; i++) {
        input = br.readLine().split(" ");
        for (int j = 0; j < 19; j++) {
            board[i][j] = Integer.parseInt(input[j]);
        }
    }
}

// dfs - 스택오버플로우
private static boolean dfs(int x, int y, int depth, int color) {
    if (x < 0 || x >= 19 || y < 0 || y >= 19) return false;

    if (board[x][y] == 0) {
        if (depth == 5) return true;
        return false;
    }

    if (board[x][y] == color) depth++;

    dfs(x - 1, y, depth, color);   // 상
    dfs(x + 1, y, depth, color);   // 하
    dfs(x, y - 1, depth, color);   // 좌
    dfs(x, y + 1, depth, color);   // 우

    dfs(x + 1, y + 1, depth, color);  // 우하향
    dfs(x + 1, y - 1, depth, color);  // 좌하향
    dfs(x - 1, y - 1, depth, color);  // 좌상향
    dfs(x - 1, y + 1, depth, color);  // 우상향

    return false;
}

}