-
2017 카카오코드 예선: 보행자 천국코딩 테스트/Level 3 2022. 9. 13. 18:16반응형
https://school.programmers.co.kr/learn/courses/30/lessons/1832
등굣길 문제의 업그레이드입니다.
JAVA
class Solution { int MOD = 20170805; public int solution(int m, int n, int[][] cityMap) { int[][][] paths = new int[m][n][3]; paths[0][0] = new int[]{1, 0, 0}; for (var i = 0; i < m; i++) { for (var j = 0; j < n; j++) { if (cityMap[i][j] == 0) { if (i > 0) paths[i][j][0] += (paths[i - 1][j][0] + paths[i - 1][j][1]) % MOD; if (j > 0) paths[i][j][0] += (paths[i][j - 1][0] + paths[i][j - 1][2]) % MOD; } else if (cityMap[i][j] == 1) { paths[i][j] = new int[]{0, 0, 0}; } else { if (i > 0) paths[i][j][1] += (paths[i - 1][j][0] + paths[i - 1][j][1]) % MOD; if (j > 0) paths[i][j][2] += (paths[i][j - 1][0] + paths[i][j - 1][2]) % MOD; } } } return (paths[m - 1][n - 1][0] + paths[m - 1][n - 1][1] + paths[m - 1][n - 1][2]) % MOD; } }
반응형