Skip to content

Commit

Permalink
2024-09-28
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Sep 27, 2024
1 parent b2f729f commit 3205c13
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jung0115/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
| 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 |
| 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 |
| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 |
| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 |
| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 |
| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | |
55 changes: 55 additions & 0 deletions jung0115/이분탐색/Baekjoon_12015.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package jung0115.이분탐색;
// 15차시 2024.09.28.토 : 백준 - 가장 긴 증가하는 부분 수열 2(12015)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Baekjoon_12015 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());

int[] A = new int[N];
for(int i = 0; i < N; i++) {
A[i] = Integer.parseInt(st.nextToken());
}

int[] longIncrease = new int[N];
int lastIndex = 0;
longIncrease[lastIndex] = A[0];

for(int i = 1; i < N; i++) {
int num = A[i];

// 이전값보다 큼 -> 증가
if(longIncrease[lastIndex] < num) {
longIncrease[++lastIndex] = num;
}
// 이전값보다 작음
else {
int left = 0;
int right = lastIndex + 1;

while (left < right) {
int mid = (left + right) / 2;

if(longIncrease[mid] < num) {
left = mid + 1;
}
else {
right = mid;
}
}

// num보다 작은 값 중 제일 뒤에 있는 숫자의 뒤
longIncrease[left] = num;
}
}

System.out.print(lastIndex + 1);
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 3205c13

Please sign in to comment.