본문 바로가기
Problem-solving/백준

백준 - 스티커(9465번) (Python3)

by taehee.kim.dev 2020. 5. 26.

https://www.acmicpc.net/problem/9465

 

9465번: 스티커

문제 상근이의 여동생 상냥이는 문방구에서 스티커 2n개를 구매했다. 스티커는 그림 (a)와 같이 2행 n열로 배치되어 있다. 상냥이는 스티커를 이용해 책상을 꾸미려고 한다. 상냥이가 구매한 스티

www.acmicpc.net

import copy

T = int(input())

for _ in range(T):

    sticker = []

    n = int(input())

    for _ in range(2):
        line = [0]
        line.extend(list(map(int, input().split(' '))))
        sticker.append(line)

    dp = copy.deepcopy(sticker)

    for sticker_index in range(2, n + 1):
        dp[0][sticker_index] = max(dp[1][sticker_index - 2], dp[1][sticker_index - 1]) \
                               + sticker[0][sticker_index]

        dp[1][sticker_index] = max(dp[0][sticker_index - 2], dp[0][sticker_index - 1]) \
                               + sticker[1][sticker_index]

    print(max(dp[0][n], dp[1][n]))

댓글