https://school.programmers.co.kr/learn/courses/30/lessons/43105
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<vector<int>> triangle) {
//24.10.21
vector<vector<int>> dp{ triangle.front() };
dp.resize(triangle.size());
for (int i = 1; i < triangle.size(); ++i)
{
dp[i].resize(triangle[i].size());
dp[i][0] = dp[i - 1][0] + triangle[i][0];
dp[i].back() = dp[i - 1].back() + triangle[i].back();
for (int j = 1; j < triangle[i].size() - 1; ++j)
dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + triangle[i][j];
}
return *max_element(dp.back().begin(), dp.back().end());
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (깊이/너비 우선 탐색(DFS/BFS)) Lv 3. 네트워크 (2) | 2024.10.23 |
---|---|
[Programmers] (완전탐색) Lv 2. 피로도 (3) | 2024.10.23 |
[Programmers] (완전탐색) Lv 2. 소수 찾기 (0) | 2024.10.21 |
[Programmers] (정렬) Lv 2. H-Index (0) | 2024.10.17 |
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 (0) | 2024.10.17 |
댓글