티스토리 뷰

https://www.acmicpc.net/problem/12015



lower_bound를 이용해서 O(nlogn)만에 LIS를 만들 수 있다. 직접 예제들을 만들어서 동작 과정을 살펴보면 이해가 쉽다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
int main()
{
    int n,m;
    scanf("%d",&n);
    vector<int> l;
    l.push_back(-1);
    while(n--)
    {
        scanf("%d",&m);
        if(l.back()<m) l.push_back(m);
        else *lower_bound(l.begin(),l.end(),m)=m;
    }
    printf("%d\n",l.size()-1);
    return 0;
}
cs


'Algorithm > BOJ' 카테고리의 다른 글

2606 바이러스  (0) 2019.01.27
14003 가장 긴 증가하는 부분 수열 5  (0) 2018.11.14
5639 이진 검색 트리  (0) 2018.11.13
1174 줄어드는 숫자  (0) 2018.09.20
1038 감소하는 수  (0) 2018.09.20
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday