https://www.acmicpc.net/problem/2352
lower_bound(LIS + 1, LIS + Size + 1, arr[i]) - LIS;
1번쨰 파라미터: first 범위
2번쨰 파라미터: last 범위
3번쨰 파라미터: value
//참조: http://dyngina.tistory.com/16
#include<iostream>
using namespace std;
#include<algorithm>
int arr[40001];
int LIS[40001];
int n,ans=0,Size=1;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
LIS[1] = arr[1];
int tmp;
for(int i=2;i<=n;i++)
{
if (LIS[Size] < arr[i])
{
Size++;
LIS[Size] = arr[i];
continue;
}
tmp = lower_bound(LIS + 1, LIS + Size + 1, arr[i]) - LIS;
LIS[tmp] = arr[i];
}
ans = Size;
cout << ans << "\n";
return 0;
}
'백준_문제풀이' 카테고리의 다른 글
[백준]: 1541번: 잃어버린 괄호 / String (0) | 2018.10.06 |
---|---|
[백준]: 2875번: 대회 or 인턴 / 탐욕적 기법(Greedy Algorithm) (0) | 2018.10.04 |
[백준]: 10610번: 30 / 탐욕적 기법(Greedy Algorithm) (0) | 2018.10.04 |
[백준]: 5557번: 1학년 / DP(동적프로그래밍) (0) | 2018.09.27 |
[백준]: 2841번: 외계인의 기타연주 / Stack & pair (0) | 2018.09.26 |