-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHDU_2084.cpp
More file actions
44 lines (43 loc) · 713 Bytes
/
HDU_2084.cpp
File metadata and controls
44 lines (43 loc) · 713 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
43
44
#include <iostream>
using namespace std;
int main()
{
int C;
int N;
int x,y;
int arr1[100][100];
cin>>C;
for (int i=0;i<C;i++)
{
memset(arr1,0,sizeof(arr1));
cin >> N;
for (int j=0;j<N;j++)
{
for (int k=0;k<=j;k++)
{
cin >> arr1[j][k];
}
}
int max_value = arr1[0][0];
for (int j=1;j<N;j++)
{
for (int k=0;k<=j;k++)
{
if (k==0)
arr1[j][k] = arr1[j][k]+arr1[j-1][k];
else if (k==j)
arr1[j][k] = arr1[j][k]+arr1[j-1][k-1];
else
{
x = arr1[j][k]+arr1[j-1][k];
y = arr1[j][k]+arr1[j-1][k-1];
arr1[j][k] = x>y?x:y;
}
if (max_value < arr1[j][k])
max_value = arr1[j][k];
}
}
cout << max_value << endl;
}
return 0;
}