# 2631 줄 세우기 # LIS의 길이를 구하기 위한 방법 복잡도 O(Nlogn)로 구하기 N = int(input()) arr = list(int(input()) for _ in range(N)) LIS = [] LIS.append(arr[0]) temp = 0 for number in arr[1:]: for ind,val in enumerate(LIS): if number > val and number not in LIS: temp = number elif number < val and number not in LIS: LIS[ind] = number temp = 0 if temp: LIS.append(temp) temp = 0 print(N-len(LIS))
이 문제는 최장 증가 부분 순열을 활용한 문제이다. 크기대로 줄을 세우는 것이기 때문에, 주어진 배열에서, 가장 긴 증가 부분 순열을 제외하고 나머지 부분을 움직이면 정답을 구할 수 있따.
'알고리즘 > 백준' 카테고리의 다른 글
[BOJ/백준] 6593 상범 빌딩 (0) | 2021.02.17 |
---|---|
[BOJ/백준] 11054 가장 긴 바이토닉 부분 수열 (0) | 2021.02.17 |
[BOJ/백준] 2873 롤러코스터 (0) | 2021.02.16 |
[BOJ/백준] 1600 말이 되고픈 원숭이 (0) | 2021.02.16 |
[BOJ/백준] 11758 CCW (0) | 2021.02.16 |