-
Notifications
You must be signed in to change notification settings - Fork 1
/
BYTESM2.cpp
53 lines (39 loc) · 1.3 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
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <cstring>
#define ll int
#define get(a) scanf("%d", &a)
#define rep(n) for( ll i = 0; i < n; i++ )
#define repVector(v) for(vector<ll>::iterator it = v.begin(); it != v.end(); it++ )
#define all(c) c.begin(), c.end()
#define repu(a,n) for( ll i = a; i < n; i++ )
#define pb push_back
using namespace std;
int main() {
ll t;
get(t);
while(t--) {
ll h, w, a[100+5][100+5] = {0}, max = 0, b[100+5][100+5]={0};
get(h); get(w);
rep(h)
for( int j = 0; j < w; j++ )
{ get(a[i][j]); b[i][j] = a[i][j]; }
rep(h-1)
for( int j = 0; j < w; j++ ) {
if( j+1 < w )
if( b[i+1][j+1] < b[i][j] + a[i+1][j+1] )
b[i+1][j+1] = b[i][j] + a[i+1][j+1];
if( j-1 >= 0 )
if( b[i+1][j-1] < b[i][j] + a[i+1][j-1] )
b[i+1][j-1] = b[i][j] + a[i+1][j-1];
if( b[i+1][j] < b[i][j] + a[i+1][j] )
b[i+1][j] = b[i][j] + a[i+1][j];
}
rep(w)
if( b[h-1][i] > max )
max = b[h-1][i];
printf("%d\n", max );
}
}