From 49bde452bd87eaf50fd0d2845e400156d2b5546b Mon Sep 17 00:00:00 2001 From: llIllIllIllIllIllIllIllI <_@seol.pro> Date: Mon, 15 Dec 2025 23:47:43 +0900 Subject: [PATCH] =?UTF-8?q?[20251215]=20BOJ=20/=20G5=20/=20=EB=84=B4?= =?UTF-8?q?=EB=AA=A8=EB=84=B4=EB=AA=A8=20(Easy)=20/=20=EC=84=A4=EC=A7=84?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...252\250\353\204\264\353\252\250 (Easy).md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "Seol-JY/202512/15 BOJ G5 \353\204\264\353\252\250\353\204\264\353\252\250 (Easy).md" diff --git "a/Seol-JY/202512/15 BOJ G5 \353\204\264\353\252\250\353\204\264\353\252\250 (Easy).md" "b/Seol-JY/202512/15 BOJ G5 \353\204\264\353\252\250\353\204\264\353\252\250 (Easy).md" new file mode 100644 index 00000000..e9d68430 --- /dev/null +++ "b/Seol-JY/202512/15 BOJ G5 \353\204\264\353\252\250\353\204\264\353\252\250 (Easy).md" @@ -0,0 +1,42 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int N, M; + static boolean[][] grid; + static long count = 0; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + grid = new boolean[N][M]; + + backtrack(0); + System.out.println(count); + } + + static void backtrack(int pos) { + if (pos == N * M) { + count++; + return; + } + + int row = pos / M; + int col = pos % M; + + grid[row][col] = false; + backtrack(pos + 1); + + grid[row][col] = true; + if (row > 0 && col > 0 && grid[row-1][col] && grid[row][col-1] && grid[row-1][col-1]) { + grid[row][col] = false; + return; + } + backtrack(pos + 1); + grid[row][col] = false; + } +} +```