Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Frenet Coordinate
- self driving car
- 백준
- 경로생성
- 소프티어
- 선형대수
- 공유라이브러리
- GIT
- solver
- 강화학습
- DynamicProgramming
- Hybrid A star
- PathPlanning
- Dubins Path
- Motion Planning
- CUDA
- CPP
- OSQP
- C++
- path planning
- 동적라이브러리
- C
- 정적라이브러리
- Leetcode
- 수치최적화
- MDP
- Graph Neural Network
- GNN
- autonomous vehicle
- Recursion
Archives
- Today
- Total
Swimmer
LeetCode 62. Unique Path 본문
Level은 Medium으로 책정되었지만 좀 더 쉬운 난이도의 문제이다.
데이터 구조 Queue를 사용하고 Dynamic Programming 개념을 차용하면 풀 수 있다.
class Solution {
public:
int uniquePaths(int m, int n) {
int arr[100][100] = { 0 };
int AlreadyQueue[100][100] = { 0 };
queue<pair<int, int>> grid;
pair<int, int> SearchGrid;
grid.push(make_pair(0, 0));
arr[0][0] = 1;
while (!grid.empty())
{
SearchGrid = grid.front();
grid.pop();
// Go Down
if (SearchGrid.first < (m - 1)){
arr[SearchGrid.first + 1][SearchGrid.second] += arr[SearchGrid.first][SearchGrid.second];
if (AlreadyQueue[SearchGrid.first + 1][SearchGrid.second] == 0){
grid.push(make_pair(SearchGrid.first + 1, SearchGrid.second));
AlreadyQueue[SearchGrid.first + 1][SearchGrid.second] = 1;
}
else{
// Do Nothing
}
}
else{
// Do Nothing
}
// Go Right
if (SearchGrid.second < (n - 1)){
arr[SearchGrid.first][SearchGrid.second + 1] += arr[SearchGrid.first][SearchGrid.second];
if (AlreadyQueue[SearchGrid.first][SearchGrid.second + 1] == 0){
grid.push(make_pair(SearchGrid.first, SearchGrid.second + 1));
AlreadyQueue[SearchGrid.first][SearchGrid.second + 1] = 1;
}
else{
// Do Nothing
}
}
else{
// Do Nothing
}
}
return arr[m - 1][n - 1];
}
};
'코딩 문제' 카테고리의 다른 글
LeetCode 1768 Merge String Alternately (0) | 2023.07.17 |
---|---|
[LeetCode] 771, Jewels and Stones (0) | 2023.02.14 |
[LeetCode] 1720 Decode XORred Array (0) | 2023.01.29 |
[LeetCode] 728. Self Dividing Numbers, C++ (0) | 2023.01.26 |
[LeetCode] 2032. Two Out of Three, C++ (0) | 2023.01.25 |
Comments