-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1932.cpp
More file actions
42 lines (37 loc) · 729 Bytes
/
1932.cpp
File metadata and controls
42 lines (37 loc) · 729 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
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int N ;
int arr[502][502] ;
int dp[502][502] ;
int dynamic_programming()
{
int value = 0 ;
for(int i = 1 ; i <= N ; i++)
{
for(int j = 1 ; j <= i ; j++)
{
dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + arr[i][j] ;
value = max(value, dp[i][j]) ;
}
}
return value ;
}
void input()
{
cin >> N ;
fill(&arr[0][0], &arr[501][501], 0) ;
fill(&dp[0][0], &dp[501][501], 0) ;
for(int i = 1 ; i <= N ; i++)
{
for(int j = 1 ; j <= i; j++)
{
cin >> arr[i][j] ;
}
}
}
int main()
{
input() ;
int value = dynamic_programming() ;
cout << value << "\n" ;
}