-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ-31
More file actions
25 lines (25 loc) · 678 Bytes
/
Q-31
File metadata and controls
25 lines (25 loc) · 678 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
T=int(input())
for tc in range(T):
n,m=map(int,input().split())
array=list(map(int,input().split()))
dp=[]
index=0
for i in range(n):
dp.append(array[index:index+m])
index+=m
for j in range(1,m): #순서*
for i in range(n):
if i==0:
left_up=0
else:
left_up=dp[i][j]+dp[i-1][j-1]
left=dp[i][j]+dp[i][j-1]
if i==n-1:
left_down=0
else:
left_down=dp[i][j]+dp[i+1][j-1]
dp[i][j]=max(left,left_down,left_up)
result=0
for i in range(n):
result=max(result,dp[i][m-1])
print(result)