-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytesm2.cpp
41 lines (40 loc) · 1.03 KB
/
bytesm2.cpp
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
#include<cstdio>
using namespace std;
int main() {
int test;
scanf("%d", &test);
while(test--) {
int h, w;
scanf("%d %d", &h, &w);
int **array = new int*[h];
for(int i=0;i<h;++i) {
array[i] = new int[w];
for(int j=0;j<w;j++) {
scanf("%d", array[i] + j);
}
}
for(int i=1;i<h;++i) {
for(int j=0;j<w;++j) {
int val = array[i-1][j];
if(j - 1 >= 0 && array[i-1][j - 1] > val) {
val = array[i-1][j-1];
}
if(j+1 < w && array[i-1][j+1] > val) {
val = array[i-1][j+1];
}
array[i][j] += val;
}
}
int max = 0;
for(int j=0;j<w;++j) {
if(array[h-1][j] > max) {
max = array[h-1][j];
}
}
for(int i=0;i<h;++i) {
delete [] array[i];
}
delete [] array;
printf("%d\n", max);
}
}