728x90
SMALL
가장 긴 증가하는 부분 수열 시리즈는 dp로 계속 풀어왔는데,
이번에 dp로는 시간초과가나서 시간 복잡도가 더 좋은 이분탐색으로 풀었다!
원래 start, end 둬서 mid = (start+end)//2 ....이 식 시리즈 몬쥐 알져....
근데 이번엔 bisect_left를 사용해서 풀었는데
넘 간편.... 이해하기도 쉽고 코드도 간편해서 좋았다 😍
from bisect import bisect_left
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
dp = [arr[0]]
for i in range(1,n):
if arr[i]>dp[-1]:
dp.append(arr[i])
else:
dp[bisect_left(dp,arr[i])]=arr[i]
print(len(dp))
728x90
LIST
'취준시절 > 백준' 카테고리의 다른 글
[백준 2630] Python - 색종이 만들기 (0) | 2021.08.25 |
---|---|
[백준 1932] Python - 정수 삼각형 (0) | 2021.08.24 |
[백준 2667] Python - 단지번호붙이기 (0) | 2021.08.24 |
[백준 7569] Python - 토마토 (0) | 2021.08.24 |
[백준 2941] 크로아티아 알파벳 - Python (0) | 2021.08.04 |