Skip to content

Commit

Permalink
백준 11053번 가장 긴 증가하는 부분 수열
Browse files Browse the repository at this point in the history
  • Loading branch information
skysign committed Aug 22, 2024
1 parent 87f6cfb commit 5e5055e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 백준 11053번 가장 긴 증가하는 부분 수열/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
from typing import List


def solve():
N = int(sys.stdin.readline().strip())
dts: List[int] = [0] + list(map(int, sys.stdin.readline().strip().split(' ')))
dp: List[int] = [0 for _ in range(N + 1)]
answer = 0

for idx in range(1, N + 1):
mx = 0
for i2 in range(idx + 1):
if dts[i2] < dts[idx]:
mx = max(mx, dp[i2])

dp[idx] = mx + 1
answer = max(answer, dp[idx])

print(answer)


if __name__ == '__main__':
solve()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
6
10 20 10 30 20 50
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4
23 changes: 23 additions & 0 deletions 백준 11053번 가장 긴 증가하는 부분 수열/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
from pathlib import Path
from unittest import TestCase
from main import solve


class Test(TestCase):
def my_solve(self, testcase_input):
sys.stdin = open(testcase_input, 'r')
stdout = sys.stdout
sys.stdout = open('stdout.txt', 'w')
solve()
sys.stdout.close()
sys.stdout = stdout

def test_solve(self, testcase_number: str):
self.my_solve('test' + testcase_number + '.txt')
self.assertEqual(
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
Path('stdout.txt').read_text().strip())

def test1_solve(self):
self.test_solve('1')

0 comments on commit 5e5055e

Please sign in to comment.