map int input split for in range append list map int input split A1 fo

 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
N, M = map(int, input().split())
A = []
for i in range(N):
A.append(list(map(int, input().split())))
A1 = [ [0] * (M+1) for i in range(N+1)]
A2 = [ [0] * M for i in range(N)]
for i in range(N):
for j in range(M):
A1[i][j] = int(A[i][j]) + max(int(A1[i-1][j]), int(A1[i][j-1]))
if int(A1[i-1][j]) > int(A1[i][j-1]):
A2[i-1][j] = 'D'
else:
A2[i][j-1] = 'R'
print()
for i in range(N):
for j in range(M):
print(A1[i][j], end = ' ')
print()
print()
for i in range(N):
for j in range(M):
print(A2[i][j], end = ' ')
print()
print()
i = 0; j = 0
while i != N or j != M:
if A2[i][j] == 'D':
print('D' , end = ' ')
i += 1
elif A2[i][j] == 'R':
print('R', end = ' ')
j += 1