Skip to content

Commit d13f855

Browse files
committed
[BOJ] #1965. 상자 넣기 / 실버2 / 23분 / 성공
1 parent 8370880 commit d13f855

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 1. 입력받기
5+
n = int(input()) # 상자의 개수
6+
boxes = list(map(int, input().split())) # 상자의 크기 배열
7+
8+
# 2. DP 초기화
9+
dp = [1] * n # 모든 상자는 최소 자기 자신을 포함하므로 초기값 1
10+
11+
# 3. DP 계산
12+
for i in range(n): # i는 현재 상자를 가리킴
13+
for j in range(i): # j는 i 이전의 상자를 가리킴
14+
if boxes[j] < boxes[i]: # j번째 상자가 i번째 상자 안에 들어갈 수 있는 경우
15+
dp[i] = max(dp[i], dp[j] + 1) # dp 갱신: 기존 값 vs j까지의 값 + 1
16+
17+
# 4. 정답 출력
18+
print(max(dp)) # dp 배열에서 최대값이 한 번에 넣을 수 있는 최대 상자 개수

0 commit comments

Comments
 (0)