From f0d01756cf452fe25abeb161b59689702e3dc263 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Tue, 14 Oct 2025 23:27:23 +0900 Subject: [PATCH] =?UTF-8?q?[20251014]=20BOJ=20/=20G4=20/=20=ED=85=8C?= =?UTF-8?q?=ED=8A=B8=EB=A1=9C=EB=AF=B8=EB=85=B8=20/=20=EA=B9=80=EB=AF=BC?= =?UTF-8?q?=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\241\234\353\257\270\353\205\270.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "zinnnn37/202510/14 BOJ G4 \355\205\214\355\212\270\353\241\234\353\257\270\353\205\270.md" diff --git "a/zinnnn37/202510/14 BOJ G4 \355\205\214\355\212\270\353\241\234\353\257\270\353\205\270.md" "b/zinnnn37/202510/14 BOJ G4 \355\205\214\355\212\270\353\241\234\353\257\270\353\205\270.md" new file mode 100644 index 00000000..cb92e171 --- /dev/null +++ "b/zinnnn37/202510/14 BOJ G4 \355\205\214\355\212\270\353\241\234\353\257\270\353\205\270.md" @@ -0,0 +1,84 @@ +```java +import java.io.*; +import java.util.StringTokenizer; + +public class BJ_14500_테트로미노 { + + private static final int[] dx = { 0, 1, 0, -1 }; + private static final int[] dy = { 1, 0, -1, 0 }; + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N, M, ans; + private static int[][] matrix; + private static boolean[][] visited; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + ans = 0; + + matrix = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + matrix[i][j] = Integer.parseInt(st.nextToken()); + } + } + + visited = new boolean[N][M]; + } + + private static void sol() throws IOException { + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + visited[i][j] = true; + dfs(1, i, j, matrix[i][j]); + visited[i][j] = false; + } + } + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static void dfs(int depth, int cx, int cy, int tmp) throws IOException { + if (depth == 4) { + ans = Math.max(ans, tmp); + return; + } + + if (tmp + (4 - depth) * 1000 <= ans) { + return; + } + + for (int d = 0; d < 4; d++) { + int nx = cx + dx[d]; + int ny = cy + dy[d]; + + if (nx < 0 || N <= nx || ny < 0 || M <= ny || visited[nx][ny]) continue; + + // 凸 처리 - 다음칸으로 이동하지 않음으로써 중간 칸에서 분기 가능하도록 함 + if (depth == 2) { + visited[nx][ny] = true; + dfs(depth + 1, cx, cy, tmp + matrix[nx][ny]); + visited[nx][ny] = false; + } + + visited[nx][ny] = true; + dfs(depth + 1, nx, ny, tmp + matrix[nx][ny]); + visited[nx][ny] = false; + } + } + +} +``` \ No newline at end of file