on
[프로그래머스] [Level3] 등굣길 JAVA
[프로그래머스] [Level3] 등굣길 JAVA
import java.util. * ;
import java.io. * ;
import java.util.stream. * ;
public class Main {
public static void main( String [] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Solution sol = new Solution();
int [][] arr = {{ 2 , 2 }};
sol.solution( 4 , 3 ,arr);
}
}
class Solution {
int [] dx = { 1 , 0 },dy = { 0 , 1 };
int [][] map,dp;
public int solution( int m, int n, int [][] puddles) {
map = new int [n + 1 ][m + 1 ];
dp = new int [n + 1 ][m + 1 ];
for ( int [] puddle : puddles) map[puddle[ 1 ]][puddle[ 0 ]] = 1 ;
dp[ 1 ][ 1 ] = 1 ;
for ( int i = 1 ;i < = n;i + + ){
for ( int j = 1 ;j < = m;j + + ){
for ( int k = 0 ;k < dx. length ;k + + ){
int nextX = j + dx[k];
int nextY = i + dy[k];
if ( ! isRange(nextX,nextY) | | map[nextY][nextX] = = 1 ) continue ;
dp[nextY][nextX] + = dp[i][j];
dp[nextY][nextX] % = 1000000007 ;
}
}
}
return dp[n][m];
}
boolean isRange( int x, int y){
return x > = 1 & & y > = 1 & & x < map[ 0 ]. length & & y < map. length ;
}
}
from http://katastrophe.tistory.com/93 by ccl(A) rewrite - 2021-11-27 17:02:05