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 |
Tags
- XR Interaction Toolkit
- 유니티
- 트리
- 자료구조
- BFS
- 투 포인터
- Team Fortress 2
- 유니온 파인드
- 그래프
- 우선순위 큐
- 시뮬레이션
- 정렬
- 백준
- DFS
- 그리디 알고리즘
- 브루트포스
- Unreal Engine 5
- 구현
- 다이나믹 프로그래밍
- 수학
- 누적 합
- 스택
- c++
- 백트래킹
- ue5
- VR
- 문자열
- 다익스트라
- 재귀
- 알고리즘
Archives
- Today
- Total
1일1알
백준 1520번 내리막 길 C++ 본문
dp[a][b]를 a,b에서 m-1,n-1로 갈 수 있는 경우의 수로 저장했다.
dp[a][b]가 -1인 경우는 아직 검사를 안 한 경우이다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
#include <bitset>
using namespace std;
using int64 = long long;
int m, n;
int dRow[4] = { -1,0,1,0 };
int dCol[4] = { 0,1,0,-1 };
vector<vector<int>> board;
vector<vector<int>> dp;
int Dfs(int row, int col) {
int& cnt = dp[row][col];
if (row == m - 1 && col == n - 1) return cnt = 1;
if (cnt != -1) return cnt;
cnt = 0;
for (int i = 0; i < 4; i++) {
int nextRow = row + dRow[i];
int nextCol = col + dCol[i];
if (nextRow < 0 || nextRow >= m) continue;
if (nextCol < 0 || nextCol >= n) continue;
if (board[nextRow][nextCol] >= board[row][col]) continue;
cnt += Dfs(nextRow, nextCol);
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> m >> n;
board = vector<vector<int>>(m, vector<int>(n));
dp = vector<vector<int>>(m, vector<int>(n, -1));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> board[i][j];
}
}
Dfs(0, 0);
int ans = dp[0][0];
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 1937번 욕심쟁이 판다 C++ (0) | 2022.09.04 |
---|---|
백준 9466번 텀 프로젝트 C++ (0) | 2022.09.03 |
백준 16197번 두 동전 C++ (0) | 2022.09.01 |
백준 16562번 친구비 C++ (0) | 2022.08.31 |
백준 6497번 전력난 C++ (0) | 2022.08.30 |