분명 풀기 시작했을땐 12시였는데,,

# t 입력
t = int(input())
for _ in range(t):
# n 입력
n = int(input())
# sticker
s = []
# score
for _ in range(2):
s.append(list(map(int, input().split())))
# n == 1
if n == 1:
print(max(s[0][0], s[1][0]))
# n >= 2
else:
# dp 설정
dp = [
[0,0] for _ in range(100001)
]
# 초기설정
dp[1][0] = s[0][0]
dp[1][1] = s[1][0]
dp[2][0] = s[1][0] + s[0][1]
dp[2][1] = s[0][0] + s[1][1]
# dp 채워넣기
for i in range(3, n+1):
dp[i][0] = max(dp[i-2][1], dp[i-1][1]) + s[0][i-1]
dp[i][1] = max(dp[i-2][0], dp[i-1][0]) + s[1][i-1]
# 출력
print(max(dp[n]))
'Algorithm(BOJ, Python) > Dynamic Programing' 카테고리의 다른 글
| [백준_11053] 가장 긴 증가하는 부분수열 python (0) | 2022.07.04 |
|---|---|
| [백준_9095] 1,2,3 더하기 python (0) | 2022.07.03 |
| [백준_2579] 계단오르기 python (0) | 2022.07.02 |
| [백준_1463] 1로 만들기 python (0) | 2022.07.02 |
| [백준_1149] RGB거리 python (0) | 2022.07.01 |