Skip to content

Commit 83ceb2f

Browse files
authored
Merge pull request #946 from AlgorithmWithGod/LiiNi-coder
[20250921] BOJ / G4 / 줄세우기 / 이인희
2 parents 2f864d5 + 4303046 commit 83ceb2f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
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+
int[] arr = new int[n];
10+
for (int i = 0; i < n; i++) {
11+
arr[i] = Integer.parseInt(br.readLine());
12+
}
13+
14+
int[] dp = new int[n];
15+
Arrays.fill(dp, 1);
16+
int lis = 1;
17+
18+
for (int i = 0; i < n; i++) {
19+
for (int j = 0; j < i; j++) {
20+
if (arr[j] < arr[i]) {
21+
dp[i] = Math.max(dp[i], dp[j] + 1);
22+
}
23+
}
24+
lis = Math.max(lis, dp[i]);
25+
}
26+
System.out.println(n - lis);
27+
}
28+
}
29+
```

0 commit comments

Comments
 (0)