Skip to content

Commit 677a18d

Browse files
authored
Merge pull request #1591 from AlgorithmWithGod/ksinji
[20251205] BOJ / G4 / 줄세우기 / 강신지
2 parents 5836826 + 0f9626e commit 677a18d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```java
2+
import java.io.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws Exception {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
int n = Integer.parseInt(br.readLine());
8+
9+
int[] arr = new int[n];
10+
int[] dp = new int[n];
11+
12+
for (int i=0; i<n; i++){
13+
arr[i] = Integer.parseInt(br.readLine());
14+
}
15+
16+
int lis = 0;
17+
for (int i=0; i<n; i++){
18+
dp[i] = 1;
19+
for (int j=0; j<i; j++){
20+
if (arr[j] < arr[i] && dp[j]+1>dp[i]){
21+
dp[i] = dp[j]+1;
22+
lis = Math.max(lis, dp[i]);
23+
}
24+
}
25+
}
26+
27+
System.out.println(n-lis);
28+
}
29+
}
30+
```

0 commit comments

Comments
 (0)