programmers_등굣길_java
2023. 2. 28. 17:08ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/42898#
class Solution {
private final int mod = 1000000007;
public int solution(int m, int n, int[][] puddles) {
int answer = 0;
int[][] dp = new int[n+1][m+1];
int puddlesSize = puddles.length;
for(int i = 0; i<puddlesSize; i++){
if(puddles[i].length > 0){
int y = puddles[i][1];
int x = puddles[i][0];
dp[y][x] = -1;
}
}
for(int i = 1; i< n+1; i++){
for(int j = 1; j<m+1; j++){
if(dp[i][j] == -1) continue;
if(i==1 && j== 1){
dp[i][j] = 1;
continue;
}
if(dp[i][j-1] != -1){
dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
}
if(dp[i-1][j] != -1){
dp[i][j] = (dp[i-1][j] + dp[i][j])%mod;
}
}
}
answer = dp[n][m];
return answer;
}
public void printArr(long[][] map){
int height = map.length;
int width = map[0].length;
for(int i = 0; i< height; i++){
for(int j = 0; j<width; j++){
System.out.print(map[i][j] + " ");
}
System.out.println();
}
System.out.println();
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_숫자 게임_java (0) | 2023.03.01 |
---|---|
programmers_단속카메라_java (0) | 2023.03.01 |
programmers_야근 지수_java (0) | 2023.02.28 |
programmers_최고의 집합_java (0) | 2023.02.28 |
programmers_단어 변환_java (0) | 2023.02.27 |