일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 프로그래머스
- zeros
- C++
- 온라인석사
- LAA
- 개발자
- 방통대
- Deep learning
- 선형대수
- 컴퓨터과학과
- Plotting
- 기본
- mpnp
- 알고리즘
- 마니토바
- 딥러닝
- 머신러닝
- leetcode
- 방송통신대학교
- MATLAB
- 주정부이민
- 매트랩
- cpp
- omscs
- 조지아텍
- 코딩테스트
- machine learning
- LV1
- EOI
- 캐나다 영주권
Archives
- Today
- Total
Krononberg
980. Unique Paths III.cpp 본문
첫 hard 문제..
//thanks to https://www.youtube.com/watch?v=P8K26R2Ci3c&ab_channel=ShivamPatel
class Solution {
public:
int m;
int n;
int startx;
int starty;
int endx;
int endy;
int pathall;
int res =0;
void dfs(vector<vector<int>> grid,int i, int j, int path){
if(i <0 || i>=m || j <0 || j>=n || grid[i][j]==-1) return;
if(i==endx && j ==endy && path == pathall){
res++;
return;
}
grid[i][j]=-1;
path++;
dfs(grid,i+1,j,path);
dfs(grid,i,j+1,path);
dfs(grid,i-1,j,path);
dfs(grid,i,j-1,path);
}
int uniquePathsIII(vector<vector<int>>& grid) {
m = grid.size();
n = grid[0].size();
pathall = m*n;
for(int i = 0; i< grid.size(); i++){
for(int j =0; j< grid[i].size(); j++){
if(grid[i][j]==1){
startx= i;
starty= j;
}
else if (grid[i][j]==2){
endx = i;
endy = j;
}
else if (grid[i][j]==-1){
pathall--;
}
}
}
dfs(grid,startx,starty,1);
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1381. Design a Stack With Increment Operation.cpp (0) | 2021.10.07 |
---|---|
1812. Determine Color of a Chessboard Square.cpp (0) | 2021.10.07 |
1967. Number of Strings That Appear as Substrings in Word.cpp (0) | 2021.10.06 |
1089. Duplicate Zeros.cpp (0) | 2021.10.06 |
1370. Increasing Decreasing String.cpp (0) | 2021.10.06 |