-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJY_42898.java
More file actions
30 lines (25 loc) ยท 944 Bytes
/
JY_42898.java
File metadata and controls
30 lines (25 loc) ยท 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
class JY_42898 {
public int solution(int m, int n, int[][] puddles) {
int answer = 0;
int[][] dp = new int[n+1][m+1];
boolean[][] p = new boolean[n+1][m+1];
// ์ ๊ธด ๊ณณ์ ์ขํ๋ฅผ 2์ฐจ์ ๋ฐฐ์ด๋ก ์ฎ๊ธฐ๊ธฐ
for(int[] puddle: puddles) {
p[puddle[1]][puddle[0]] = true;
}
dp[0][1] = 1; // ์์์ (1,1)์ 1์ ๋์
ํ๊ธฐ ์ํ ์ด๊ธฐํ
for(int i=1; i<n+1; i++) {
for(int j=1; j<m+1; j++) {
if(p[i][j]) continue;
// ์ผ์ชฝ์์ ์ค๋ ๋ฐฉ๋ฒ + ์์์ ๋ด๋ ค์ค๋ ๋ฐฉ๋ฒ
dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % 1_000_000_007;
}
}
// for(int i=0; i<n+1; i++) {
// System.out.println(Arrays.toString(dp[i]));
// }
answer = dp[n][m] % 1_000_000_007;
return answer;
}
}