2019. 8. 7. 18:50
728x90

Maximum path sum I

Problem 18

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.

3
7 4
4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bottom of the triangle below:

75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)

최상단 시작 지점에서 가장 아래층까지 내려가면서 거치는 경로 중 값의 합이 가장 큰 값은 몇인가.

목적지가 어디가 될지 알 수 없으므로 목적이 후보에서부터 출발지로 거슬러 올라가는 방식으로 구해야 한다. i + 1의 값과 i의 값을 합하여 합계가 큰 쪽은 남겨두는 방식으로 출발지점까지 거슬러 올라가면 합계가 가장 큰 값을 빠르게 구할 수 있다.
설명으로 나온 숫자 배열을 예로 들면 아래와 같이 진행된다.

이와 같은 방식으로 진행하면 결과 값을 빠르게 얻을 수 있다.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

백준 1018 - 체스판 다시 칠하기  (0) 2019.08.08
백준 7568 - 덩치  (0) 2019.08.08
백준 2231 - 분해합  (0) 2019.08.07
백준 2798 - 블랙잭  (0) 2019.08.07
백준 1002 - 터렛  (0) 2019.08.06
Posted by 아야카