-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path120.cpp
More file actions
35 lines (27 loc) · 706 Bytes
/
120.cpp
File metadata and controls
35 lines (27 loc) · 706 Bytes
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
32
33
34
#include<iostream>
#include<vector>
#define INT_MAX 924092437
int minimumTotal(std::vector<std::vector<int>>& triangle) {
std::vector<int> dp = triangle.back();
for (int i = triangle.size() - 2; i >= 0; --i) {
for (int j = 0; j < triangle[i].size(); ++j) {
dp[j] = std::min(dp[j], dp[j + 1]) + triangle[i][j];
}
}
return dp[0];
}
int main() {
std::vector<std::vector<int>> triangle = {
{ 2 },
{ 3,4 },
{ 6,5,7 },
{ 4,1,8,3 }
};
// std::vector<std::vector<int>> triangle = {
// { -1 },
// { 2,3 },
// { 1,-1,-3 },
// };
std::cout << minimumTotal(triangle);
std::cin.get();
}