Skip to content

Commit 6e365bd

Browse files
committed
백준 1932번 정수 삼각형
문제 링크: https://www.acmicpc.net/problem/1932
1 parent d858333 commit 6e365bd

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
from typing import List
3+
4+
5+
def solve():
6+
n = int(sys.stdin.readline().strip())
7+
dts: List[List[int]] = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
8+
dp: List[List[int]] = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
9+
10+
for row_idx in range(1, n + 1):
11+
line = list(map(int, sys.stdin.readline().strip().split(' ')))
12+
for col_idx in range(1, row_idx + 1):
13+
dts[row_idx][col_idx] = line[col_idx - 1]
14+
15+
dp[1][1] = dts[1][1]
16+
17+
for row_idx in range(2, n + 1):
18+
for col_idx in range(1, row_idx + 1):
19+
dp[row_idx][col_idx] = dts[row_idx][col_idx] + max(dp[row_idx - 1][col_idx], dp[row_idx - 1][col_idx - 1])
20+
21+
print(max(dp[n]))
22+
23+
24+
if __name__ == '__main__':
25+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
7
3+
3 8
4+
8 1 0
5+
2 7 4 4
6+
4 5 2 6 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
from pathlib import Path
3+
from unittest import TestCase
4+
from main import solve
5+
6+
7+
class Test(TestCase):
8+
def my_solve(self, testcase_input):
9+
sys.stdin = open(testcase_input, 'r')
10+
stdout = sys.stdout
11+
sys.stdout = open('stdout.txt', 'w')
12+
solve()
13+
sys.stdout.close()
14+
sys.stdout = stdout
15+
16+
def test_solve(self, testcase_number: str):
17+
self.my_solve('test' + testcase_number + '.txt')
18+
self.assertEqual(
19+
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
20+
Path('stdout.txt').read_text().strip())
21+
22+
def test1_solve(self):
23+
self.test_solve('1')

0 commit comments

Comments
 (0)