상세 컨텐츠

본문 제목

[프로그래머스] 등굣길 : unsolved

💯ProblemSolving/문제 풀이-Java

by :부셔져버린개발자 2025. 1. 15. 12:19

본문

       문제 요약        

- 문제

https://school.programmers.co.kr/learn/courses/30/lessons/42898

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

         아이디어        

dp라는 걸 바로 알았지만

(1) n과 m  바꾸고

(2) 좌표범위 (1,1) - (n,m) 인걸 (0,0)부터인걸로 착각해서 고생한 문제 

 

         소스코드        

 

import java.util.*;
class Solution {
    public int solution(int m, int n, int[][] puddles) {
        int answer = 0;
        
        boolean[][] isPossible = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            Arrays.fill(isPossible[i], true);
        }
        for(int i = 0; i < puddles.length; i++) {
            isPossible[puddles[i][1]-1][puddles[i][0]-1] = false;
        }
        int[][] dp = new int[n][m];
        dp[0][0] = 1;

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(!isPossible[i][j]){continue;}
                if(j > 0) {
                    dp[i][j] += dp[i][j-1];                    
                    dp[i][j] %= 1_000_000_007;
                }
                if(i > 0) {
                    dp[i][j] += dp[i-1][j];               
                    dp[i][j] %= 1_000_000_007;
                }
            }
        }
        answer = dp[n-1][m-1];
            
        return answer;
    }

}

 

728x90

관련글 더보기