Search
Duplicate

스티커

생성일
2021/03/20 18:19
번호
9465
유형
dp

코드 (Python)

시간 : 1224 ms

메모리 : 44828 KB

n = int(input()) k = [] for b in range(n): l = [[],[]] m = int(input()) l[0] = list(map(int, input().split())) l[1] = list(map(int, input().split())) upl = [] downl = [] for i in range(m): upl += [l[i%2][i]] downl += [l[(i+1)%2][i]] if m >= 2: upl[1] += upl[0] downl[1] += downl[0] for i in range(2,m): upl[i] += max(upl[i-1],downl[i-2]) downl[i] += max(downl[i-1],upl[i-2]) k += [max(downl[-1],upl[-1])] for p in k: print(p)
Python
복사