[Silver II] Title: 가장 긴 증가하는 부분 수열, Time: 68 ms, Memory: 34536 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-02-28 18:27:36 +09:00
parent c68b7fbc29
commit 3b790cde45
2 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# [Silver II] 가장 긴 증가하는 부분 수열 - 11053
[문제 링크](https://www.acmicpc.net/problem/11053)
### 성능 요약
메모리: 34536 KB, 시간: 68 ms
### 분류
다이나믹 프로그래밍
### 제출 일자
2025년 2월 28일 18:27:19
### 문제 설명
<p>수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오.</p>
<p>예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {<strong>10</strong>, <strong>20</strong>, 10, <strong>30</strong>, 20, <strong>50</strong>} 이고, 길이는 4이다.</p>
### 입력
<p>첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000)이 주어진다.</p>
<p>둘째 줄에는 수열 A를 이루고 있는 A<sub>i</sub>가 주어진다. (1 ≤ A<sub>i</sub> ≤ 1,000)</p>
### 출력
<p>첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다.</p>

View File

@@ -0,0 +1,19 @@
import sys
import math
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
def lis_length_dp(nums):
dp = [1]*n # dp[i] = nums[i]가 마지막 원소일 때 LIS 길이
for i in range(n):
for j in range(i):
if nums[j] < nums[i]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)
print(lis_length_dp(a))