-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LIS / ( lower_bound , upper_bound ) #23
Comments
함정 문제백준 11055번 가장 큰 증가 부분 수열 https://www.acmicpc.net/problem/11055 7570번: 줄세우기 https://www.acmicpc.net/problem/2631 LIS 문제 모음 : https://github.com/hotehrud/acmicpc/tree/master/algorithm/lis |
Lower_bound원하는 값 k 이상의 값이 처음으로 나오는 인덱스를 리턴주의 ! : 만약 모든 원소가 k 보다 작으면 n+1 을 출력하게 되는데 그렇기 때문에 !!!===> 처음 구간을 잡을때 [1,n+1] 로 잡을것!!!!!!!!!!!!!!!!!
Upper_bound원하는 값 k를 초과한 값이 처음 나오는 인덱스 리턴
|
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N^2 방법
dp[i] = data[i] 를 마지막 원소로 하는 증가 부분 수열의 최장 길이
Lower Bound 를 이용한 방법 / nlogn
dp 는 길이가 x인 최장증가수열의 마지막 수의 최소값을 의미
ex ) 10, 20, 40, 30, 70, 50, 60
고려해야 할 부분
lower_bound 방식 ( lis 요소들 추적 가능한 방법! )
위의 방식은 LIS 길이를 구하는 방식이지만 해당 길이의 요소를 알수없다. ( 주의 )
ans 라는 pair 배열을 새로 만들고 정의해야함
ans[].dx : 실제 그 값이 들어갈수 있는 위치
ans[].dy : 실제 해당하는 값
실제 lis 배열을 구하는 알고리즘을 보자
예를들면 다음과 같다.
1 6 2 5 7 3 5 6인 경우
ans배열에는 다음과 같이 들어간다.
dx :: 0 1 1 2 3 2 3 4
dy :: 1 6 2 5 7 3 5 6
이 값을 dx를 기준으로 뒤에서 부터 조사해오면
dx가 4일때 (6) - > dx가 3일때 (5) -> dx가 2일때 (3)
-> dx가 1일때 (2) -> dx가 0일때(1)이다.
이것을 스택에 담아 역출력하면 1,2,3,5,6이라는 실제 배열을 구할 수 있다.
lower_bound 란?
인덱스 트리를 이용한 방법 / nlogn
설명 : https://m.blog.naver.com/kks227/220791986409
(그림 확인)
A[i]=x 인 i에 대해 구간 [0,i]에 지금까지 존재하는 lis 길이 +1이 x로 끝나는 lis 길이
주의 사항
==> 중복되는 값들 중에서는 가장 큰 인덱스 부터 방문해야 함!!!
==> 정렬할때 값 기준 오름차순 / 같은 값있을 경우는 인덱스 기준 내림차순
The text was updated successfully, but these errors were encountered: