Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cea060c

Browse files
committed
이예진: [BOJ] 2352 반도체 설계_241127
1 parent 8789b96 commit cea060c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

‎BOJ/1000-5000번/YJ_2352.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class YJ_2352 {
5+
static List<Integer> lis = new ArrayList<>();
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int n = Integer.parseInt(br.readLine());
9+
StringTokenizer st = new StringTokenizer(br.readLine());
10+
//초기화
11+
int[] connection = new int[n+1];
12+
for(int i=1; i<n+1; i++){
13+
connection[i] = Integer.parseInt(st.nextToken());
14+
}
15+
16+
lis.add(0);
17+
//LIS
18+
for(int i = 1; i<connection.length; i++){
19+
if(lis.get(lis.size()-1) < connection[i]){
20+
lis.add(connection[i]); //최장 증가 원소 추가
21+
}else{
22+
int index = binarySearch(lis.size()-1, connection[i]);
23+
lis.set(index, connection[i]); //★현재 원소가 들어갈 위치를 찾았다면 현재 원소와 가장 가깝고 큰 원소를 제거
24+
}
25+
}
26+
int result = lis.size()-1;
27+
System.out.println(result == 0 ? 1 : result);
28+
}
29+
30+
//타겟이 최장 증가 원소들 중 어느 위치에 들어가면 적절한지 매개변수 탐색
31+
public static int binarySearch(int end, int target){
32+
int start = 1;
33+
while(start < end){
34+
int mid = (start + end)/2; //mid 가 선을 연결할 수 있는지, 없는지
35+
if(lis.get(mid) < target){
36+
start = mid + 1; //start 간격을 조정하면 mid 가 커진다 > 더 넓은 범위 에서 연결할 수 있는 선을 찾는다
37+
}else{
38+
end = mid; //end 간격을 조정하면 mid 가 작아진다 > 연결을 더 많이 할 수 있다
39+
}
40+
}
41+
return end;
42+
}
43+
//lower bound: mid 값보다 크거나 같을때 end 는 중간값과 같은 위치에 있음
44+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /