카테고리 없음
[C] 백준 - 12015번: 가장 긴 증가하는 부분 수열 2
C0MPAS
2024. 6. 5. 13:21
6월 5일(수) - 이분 탐색(12015번)
https://www.acmicpc.net/problem/12015
최초 생각 정리
문제점
풀이 - 1
(C언어 풀이)
(풀이출처 -> )
풀이 - 2
(java 풀이)
(풀이출처 -> https://st-lab.tistory.com/285)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
int[] LIS = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++)
{
arr[i] = Integer.parseInt(st.nextToken());
}
LIS[0] = arr[0];
int length_of_LIS = 1;
for(int i=1; i<N; i++)
{
int key = arr[i];
if(LIS[length_of_LIS - 1] < key)
{
length_of_LIS++;
LIS[length_of_LIS - 1] = key;
}
else
{
int left = 0;
int right = length_of_LIS;
while (left < right)
{
int mid = (left + right)/2;
if(LIS[mid] < key)
{
left = mid +1 ;
}
else
{
right = mid;
}
}
LIS[left] = key;
}
}
System.out.println(length_of_LIS);
}
}