map int input split for in range append list map int input split path

 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
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
path = []
b = []
for i in range(n + 1): b.append(list(0 for i in range(m + 1)))
b[1][1] = a[0][0]
path = []
for i in range(n):
for j in range(m):
b[i + 1][j + 1] = a[i][j] + max(b[i][j + 1], b[i + 1][j])
print(b[-1][-1])
b.pop(0)
for i in range(n):
b[i].pop(0)
b = b[::-1]
for i in range(n):
b[i] = b[i][::-1]
for i in range(n):
for j in range(m):
if j < (m - 1) and i < (m - 1):
if b[i][j + 1] > b[i + 1][j]:
path.append('R')
elif b[i][j + 1] < b[i + 1][j]:
path.append('D')
print(*path)