Skip to content

Commit 4001106

Browse files
authored
[20250728] BOJ / G4 / 가장 긴 바이토닉 부분 수열 / 이준희
1 parent 4285c04 commit 4001106

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) throws Exception {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st;
10+
11+
int n = Integer.parseInt(br.readLine());
12+
13+
int[] arr = new int[n];
14+
int[] dp1 = new int[n];
15+
int[] dp2 = new int[n];
16+
17+
st = new StringTokenizer(br.readLine());
18+
for (int i = 0; i < n; i++) {
19+
arr[i] = Integer.parseInt(st.nextToken());
20+
}
21+
22+
for (int i = 0; i < n; i++) {
23+
dp1[i] = 1;
24+
for (int j = 0; j < i; j++) {
25+
if (arr[j] < arr[i]) {
26+
dp1[i] = Math.max(dp1[i], dp1[j] + 1);
27+
}
28+
}
29+
}
30+
31+
for (int i = n - 1; i >= 0; i--) {
32+
dp2[i] = 1;
33+
for (int j = n - 1; j >= i; j--) {
34+
if (arr[j] < arr[i]) {
35+
dp2[i] = Math.max(dp2[i], dp2[j] + 1);
36+
}
37+
}
38+
}
39+
40+
int result = 0;
41+
42+
for (int i = 0; i < n; i++) {
43+
result = Math.max(result, dp1[i] + dp2[i] - 1);
44+
}
45+
46+
System.out.println(result);
47+
}
48+
}
49+
50+
```

0 commit comments

Comments
 (0)