diff --git "a/ShinHeeEul/202503/20 BOJ G5 4\354\231\200 7" "b/ShinHeeEul/202503/20 BOJ G5 4\354\231\200 7.md" similarity index 100% rename from "ShinHeeEul/202503/20 BOJ G5 4\354\231\200 7" rename to "ShinHeeEul/202503/20 BOJ G5 4\354\231\200 7.md" diff --git "a/ShinHeeEul/202504/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2602.md" "b/ShinHeeEul/202504/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2602.md" new file mode 100644 index 00000000..ee9840fa --- /dev/null +++ "b/ShinHeeEul/202504/04 BOJ G4 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2602.md" @@ -0,0 +1,86 @@ +```java +import java.util.*; +import java.io.*; + +class Main { + + + static int[] di = {0,1,1}; + static int[] dj = {1,0,1}; + static boolean[][] map; + static int N; + public static void main(String args[]) throws Exception { + + N = read(); + + map = new boolean[N][N]; + + for(int i = 0; i < N; i++) { + for(int j = 0; j < N; j++) map[i][j] = read() == 1; + } + + long[][][] dp = new long[N][N][3]; + + dp[0][1][0] = 1; + + for(int i = 0; i < N; i++) { + for(int j = 0; j < N; j++) { + int ni = i + 1; + int nj = j + 1; + // 가로로 놓여있을때 + if(check(i, nj, true)) dp[i][nj][0] += dp[i][j][0]; + if(check(ni, nj, false)) dp[ni][nj][2] += dp[i][j][0]; + + // 세로로 놓여있을때 + if(check(ni, j, true)) dp[ni][j][1] += dp[i][j][1]; + if(check(ni, nj, false)) dp[ni][nj][2] += dp[i][j][1]; + + // 대각선으로 놓여있을 때 + if(check(ni, j, true)) dp[ni][j][1] += dp[i][j][2]; + if(check(i, nj, true)) dp[i][nj][0] += dp[i][j][2]; + if(check(ni, nj, false)) dp[ni][nj][2] += dp[i][j][2]; + + } + } + +// for(int i = 0; i < N; i++) { +// for(int j = 0; j < N; j++) { +// System.out.print(dp[i][j][0] + "" + dp[i][j][1] + "" + dp[i][j][2] + " "); +// } +// System.out.println(); +// } +// + System.out.println(dp[N-1][N-1][0] + dp[N-1][N-1][1] + dp[N-1][N-1][2]); + } + + public static boolean check(int i, int j, boolean b) { + if(b)return i >= 0 && j >= 0 && i < N && j < N && !map[i][j]; + return i >= 0 && j >= 0 && i < N && j < N && !map[i][j] && !map[i-1][j] && !map[i][j-1]; + } + + + private static int read() throws Exception { + int c; + int n = 0; + boolean negative = false; + + while ((c = System.in.read()) <= 32) { + if (c == -1) return -1; + } + + if (c == '-') { + negative = true; + c = System.in.read(); + } + + do { + n = n * 10 + (c - '0'); + c = System.in.read(); + } while (c > 32); + + return negative ? -n : n; + } + + +} +```