forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW_42898.java
More file actions
29 lines (25 loc) · 826 Bytes
/
HW_42898.java
File metadata and controls
29 lines (25 loc) · 826 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
// 시간 복잡도 : 주어진 내에서 구현 가능
import java.util.*;
import java.io.*;
// 오른쪽과 아래만 움직여서
// 집에서 학교까지 갈 수 있는 최단경로의 개수
class HW_42898 {
public int solution(int m, int n, int[][] puddles) {
int dp[][] = new int[n+1][m+1];
int MOD = 1000000007;
for(int i=0; i<puddles.length; i++){
dp[puddles[i][1]][puddles[i][0]] = -1;
}
dp[1][1] = 1; // (1, 1) 설정
for(int i=1; i<n+1; i++){
for(int j=1; j<m+1; j++){
if(dp[i][j] == -1){ // 물에 잠긴 지역이라면
dp[i][j] = 0;
continue;
}
dp[i][j] += (dp[i-1][j]+dp[i][j-1])%MOD;
}
}
return dp[n][m];
}
}