From 5a47453a475e519536c1a42385fcaa93f6c4fd0e Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Tue, 4 Feb 2025 10:15:06 +0900 Subject: [PATCH] =?UTF-8?q?[20250204]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=B4=ED=94=84=20=EC=98=AE=EA=B8=B0=EA=B8=B0=20?= =?UTF-8?q?2=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\230\256\352\270\260\352\270\260 2.md" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "Seol-JY/202502/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 2.md" diff --git "a/Seol-JY/202502/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 2.md" "b/Seol-JY/202502/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 2.md" new file mode 100644 index 00000000..70dbb2a4 --- /dev/null +++ "b/Seol-JY/202502/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 2.md" @@ -0,0 +1,49 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + private static final int H = 0; + private static final int V = 1; + private static final int D = 2; + + private static int SIZE; + static int[][] map; + static long[][][] dp; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + SIZE = Integer.parseInt(br.readLine()); + + map = new int[SIZE + 1][SIZE + 1]; + dp = new long[3][SIZE + 1][SIZE + 1]; + + StringTokenizer st; + for (int i = 1; i <= SIZE; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= SIZE; j++) { + if (1 == Integer.parseInt(st.nextToken())) { + map[i][j] = 1; + } + } + } + + dp[H][1][2] = 1; + + for (int i = 1; i <= SIZE; i++) { + for (int j = 1; j <= SIZE; j++) { + if (i == 1 && j <= 2) continue; + + if (map[i][j] == 1) continue; + dp[H][i][j] = dp[H][i][j-1] + dp[D][i][j-1]; + dp[V][i][j] = dp[V][i-1][j] + dp[D][i-1][j]; + + if(map[i][j-1] == 1 || map[i-1][j] == 1) continue; + dp[D][i][j] = dp[H][i-1][j-1] + dp[V][i-1][j-1] + dp[D][i-1][j-1]; + } + } + + System.out.println(dp[H][SIZE][SIZE] + dp[V][SIZE][SIZE] + dp[D][SIZE][SIZE]); + } +} +```