Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jis1218 committed Feb 24, 2020
1 parent 8ade8a3 commit 9d9c949
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions programmers/연습문제/보행자 천국/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
```java
class Solution {
int MOD = 20170805;
public int solution(int m, int n, int[][] cityMap) {
int memo[][] = new int[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
memo[i][j] = -1;
}
}
int a = helper(cityMap, memo, m-2, n-1, true);
int b = helper(cityMap, memo, m-1, n-2, false);
return (a + b) % MOD;
}
public int helper(int[][] cityMap, int[][] memo, int m, int n, boolean flow){
if(m<0 || n<0 || cityMap[m][n]==1 ) return 0;
if(m==0 && n==0) return 1;
if(cityMap[m][n]==2){
if(flow) return helper(cityMap, memo, m-1, n, true);
else return helper(cityMap, memo, m, n-1, false);
}
if(memo[m][n]!=-1) return memo[m][n] % MOD;
memo[m][n] = helper(cityMap, memo, m-1, n, true) +
helper(cityMap, memo, m, n-1, false);
return memo[m][n] % MOD;
}
}
```

0 comments on commit 9d9c949

Please sign in to comment.