백준 1932 정수 삼각형

김민영·2023년 1월 10일
0

알고리즘

목록 보기
50/125

과정

  • 위에 있는 왼쪽, 오른쪽 수 중 큰 수를 밑에 더해가면서 리스트를 업데이트 한다.
    • 맨 앞의 항목은 오른쪽의 값만, 맨 뒤의 항목은 왼쪽의 값만 더해나간다.
import sys
input = sys.stdin.readline
N = int(input())
inp_lst = list(map(int, input().split()))
if N == 1:
    print(inp_lst[0])
    exit()
for i in range(2, N+1):
    new_inp = list(map(int, input().split()))
    new_inp[0] += inp_lst[0]
    for j in range(1, i-1):
        new_inp[j] += max(inp_lst[j-1], inp_lst[j])
    new_inp[-1] += inp_lst[-1]
    inp_lst = new_inp
print(max(new_inp))
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글