From 79250576771fbf552bc112baf668d750756c1654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EC=84=A0=EC=95=84?= Date: Sun, 22 Dec 2024 00:49:22 +0900 Subject: [PATCH] =?UTF-8?q?Add=20#7=20=EB=93=B1=EA=B5=A3=EA=B8=B8=20-=20?= =?UTF-8?q?=EC=A7=80=EC=84=A0=EC=95=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\247\200\354\204\240\354\225\204.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "dp/\353\223\261\352\265\243\352\270\270/\354\247\200\354\204\240\354\225\204.java" diff --git "a/dp/\353\223\261\352\265\243\352\270\270/\354\247\200\354\204\240\354\225\204.java" "b/dp/\353\223\261\352\265\243\352\270\270/\354\247\200\354\204\240\354\225\204.java" new file mode 100644 index 0000000..b5a0011 --- /dev/null +++ "b/dp/\353\223\261\352\265\243\352\270\270/\354\247\200\354\204\240\354\225\204.java" @@ -0,0 +1,30 @@ +class Solution { + private static final int NUM = 1000000007; + int[][] dp; + public int solution(int m, int n, int[][] puddles) { + dp = new int[m][n]; + // 초기값 설정 + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + dp[i][j] = -1; + } + } + // 웅덩이 설정 + for (int[] puddle : puddles) { + dp[puddle[0] - 1][puddle[1] - 1] = 0; + } + dp[0][0] = 1; + return dfs(m-1, n-1); + } + + public int dfs(int x, int y) { + if (x < 0 || y < 0) { + return 0; + } + if (dp[x][y] != -1) { + return dp[x][y]; + } + dp[x][y] = (dfs(x - 1, y) + dfs(x, y-1)) % NUM; + return dp[x][y]; + } +}