[Mathematics] 최장 증가 수열

LIS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <vector>
using namespace std;
#define INF -987654321
#define MAXLEN 10
vector<int> vt;
int main(int argc, char** argv){
int arr[MAXLEN] = {10, 20, 40, 25, 20, 50, 30, 70, 85};
vt.push_back(-INF);
for(int i=0; i<MAXLEN; i++){
if(vt.back()<arr[i])
vt.push_back(arr[i]);
else{
auto it = lower_bound(vt.begin(),vt.end(),arr[i]);
*it = arr[i];
}
}
printf("LIS : %d\n",vt.size());
return 0; //정상종료시 반드시 0을 리턴해야 합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/21/Algorithm/lis/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.