| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- ROS2
- 밑바닥부터 시작하는 딥러닝2
- DFS
- Baekjoon
- Operating System
- deep learning
- CNN
- Machine Learning
- do it! 알고리즘 코딩테스트: c++편
- Process
- Optimization
- RNN
- computer vision
- cs231n
- SQLD
- Gentoo2
- C++
- Python
- On-memory file system
- ubuntu 22.04
- Data Science
- Linux
- System Call
- Humble
- file system
- BFS
- Seoul National University
- CPP
- assignment1
- assignment2
Archives
- Today
- Total
newhaneul
[Baekjoon/C++] 24418번: 알고리즘 수업 - 행렬 경로 문제 1(Dynamic Programming) 본문
1. Programming/BaekJoon
[Baekjoon/C++] 24418번: 알고리즘 수업 - 행렬 경로 문제 1(Dynamic Programming)
뉴하늘 2026. 1. 4. 18:00728x90



# Baekjoon 24418번: 알고리즘 수업 - 행렬 경로 문제 1
#include <iostream>
#include <vector>
using namespace std;
int rec = 0;
int dp = 0;
int matrix_path_rec(vector<vector<int>>& m, int i, int j);
int matrix_path(vector<vector<int>>& m, int n) {
return matrix_path_rec(m, n, n);
}
int matrix_path_rec(vector<vector<int>>& m, int i, int j) {
if (i == 0 or j == 0) {
rec++;
return 0;
}
else
return m[i][j] + max(matrix_path_rec(m, i - 1, j), matrix_path_rec(m, i, j - 1));
}
int matrix_path_dp(vector<vector<int>>& m, int n) {
for (int i = 0; i < n + 1; i++) m[i][0] = 0;
for (int j = 1; j < n + 1; j++) m[0][j] = 0;
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < n + 1; j++) {
m[i][j] = m[i][j] + max(m[i - 1][j], m[i][j - 1]);
dp++;
}
}
return m[n][n];
}
int main(void) {
int n;
cin >> n;
vector<vector<int>> m(n + 1, vector<int>(n + 1));
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < n + 1; j++)
cin >> m[i][j];
}
vector<vector<int>> m2 = m;
matrix_path(m, n);
matrix_path_dp(m2, n);
cout << rec << " " << dp;
return 0;
}
728x90
'1. Programming > BaekJoon' 카테고리의 다른 글
| [Baekjoon/Python] 2156번: 포도주 시식(Dynamic Programming) (3) | 2024.10.25 |
|---|---|
| [Baekjoon/Python] 1149번: RGB거리(Dynamic Programming) (3) | 2024.10.24 |
| [Baekjoon/Python] 10026번: 적록색약(BFS) (2) | 2024.10.23 |
| [Baekjoon/Python] 16928번: 뱀과 사다리 게임(BFS) (3) | 2024.10.18 |
| [Baekjoon/Python] 1759번: 암호 만들기(BackTracking) (0) | 2024.10.11 |
