Skip to content

Commit f456fe7

Browse files
authored
[Week02] BOJ 1965: 상자넣기
[Week02] BOJ 1965: 상자넣기
2 parents acd1ec1 + f86c926 commit f456fe7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
5+
// 상자 넣기
6+
// 알고리즘 종류 확인
7+
public class BOJ_1965 {
8+
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
12+
int N = Integer.parseInt(br.readLine());
13+
14+
int [] arr = new int[N+1];
15+
String [] s = br.readLine().split(" ");
16+
int [] dp = new int[N+1];
17+
18+
for(int i=1; i<=N; i++){
19+
arr[i] = Integer.parseInt(s[i-1]);
20+
dp[i] = 1;
21+
}
22+
23+
for(int i=2; i<=N; i++){
24+
for(int j=1; j<i; j++){
25+
if(arr[i] > arr[j]){
26+
dp[i] = Math.max(dp[j]+1, dp[i]);
27+
}
28+
}
29+
}
30+
31+
int max = 0;
32+
for(int i=1; i<=N; i++){
33+
if(max < dp[i]){
34+
max = dp[i];
35+
}
36+
}
37+
38+
System.out.println(max);
39+
}
40+
}

0 commit comments

Comments
 (0)