본문 바로가기
BOJ

[BinarySearch w/LIS] 반도체설계

by YGSEO 2020. 12. 6.
728x90

LIS 설명 블로그

seungkwan.tistory.com/8

 

가장 긴 증가하는 부분 수열 (Longest Increasing Subsequence)

어떠한 수열에서 가장 긴 증가하는 부분 수열(Longest Increasing Subsequence)를 찾는 문제는 꽤나 유명한 문제입니다. 다이나믹 프로그래밍을 공부할 때 예시로 자주 나오는 문제이고, 프로그래밍 대회

seungkwan.tistory.com

# 2352, 반도체 설계
import sys
input = sys.stdin.readline

def lower_bound(s, e, v):
    while s < e:
        m = (s+e) // 2
        if lst1[m] < v:
            s = m + 1
        else:
            e = m
    return e

n = int(input())
port = list(map(int, input().split()))
lst1 = []

for i in range(n):
    if i == 0:
        lst1.append(port[i])
    else:
        if port[i] > lst1[-1]:
            lst1.append(port[i])
        else:
            tmp = lower_bound(0, len(lst1), port[i])
            lst1[tmp] = port[i]

print(len(lst1))

코드 출처: li-fo.tistory.com/56

 

파이썬 | 백준 | 2352 | 반도체 설계

solution 1. 1365 꼬인 전깃줄하고 비슷한 유형 https://li-fo.tistory.com/50?category=921537 2. LIS의 길이 출력 # 2352, 반도체 설계 import sys input = sys.stdin.readline def lower_bound(s, e, v): whil..

li-fo.tistory.com

 

 

728x90

'BOJ' 카테고리의 다른 글

[BinarySearch] 개똥벌레  (0) 2020.12.08
[BinarySearch] 게임 1072  (0) 2020.12.08
[BinarySearch] K번째 수 1300번  (0) 2020.12.03
[BinarySearch] 가장 긴 증가하는 부분 수열 2  (0) 2020.12.03
[BinarySearch] 수들의 합  (0) 2020.12.01

댓글