-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_1932.cpp
More file actions
60 lines (50 loc) · 1.15 KB
/
bj_1932.cpp
File metadata and controls
60 lines (50 loc) · 1.15 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <stack>
#include <queue>
#include <string>
using namespace std;
int main() {
int N;
int arr[501][501] = {};
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> N;
for(int i = 0; i<N; i++) {
for(int j = 0; j<=i; j++) {
int temp;
cin >> temp;
arr[i][j] = temp;
}
}
int DP[501][501] = {};
DP[0][0] = arr[0][0];
for(int i = 1; i < N; i++) {
for(int j = 0; j<= i; j++) {
DP[i][j] = arr[i][j];
}
}
for(int i = 1; i<N; i++ ) {
for(int j = 0; j<= i; j++) {
if(DP[i][j] < DP[i-1][j] + arr[i][j]) {
DP[i][j] = DP[i-1][j] + arr[i][j];
}
if(j-1 >= 0) {
if(DP[i][j] < DP[i-1][j-1] + arr[i][j]) {
DP[i][j] = DP[i-1][j-1] + arr[i][j];
}
}
}
}
int Max = 0;
for(int i = 0; i<N; i++)
{
if(DP[N-1][i] > Max)
Max = DP[N-1][i];
}
cout << Max << "\n";
return 0;
}