Skip to content

Commit 8fea871

Browse files
authored
[20251030] PGM / LV3 / 등굣길 / 강신지
1 parent 58960cb commit 8fea871

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ksinji/202510/30 PGM 등굣길.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
class Solution {
3+
static final int MOD = 1000000007;
4+
public int solution(int m, int n, int[][] puddles) {
5+
int[][] dp = new int[n+1][m+1];
6+
7+
dp[1][1] = 1;
8+
9+
for (int[] p: puddles){
10+
dp[p[1]][p[0]] = -1;
11+
}
12+
13+
for (int i=1; i<n+1; i++){
14+
for (int j=1; j<m+1; j++){
15+
if (i==1 && j==1){
16+
continue;
17+
}
18+
19+
if (dp[i][j] == -1) {
20+
continue;
21+
} else if (dp[i-1][j] == -1) {
22+
dp[i][j] = dp[i][j-1]%MOD;
23+
} else if (dp[i][j-1] == -1) {
24+
dp[i][j] = dp[i-1][j]%MOD;
25+
} else {
26+
dp[i][j] = (dp[i][j-1]+dp[i-1][j])%MOD;
27+
}
28+
}
29+
}
30+
31+
return dp[n][m];
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)