-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion4.java
More file actions
48 lines (37 loc) · 1.25 KB
/
Copy pathQuestion4.java
File metadata and controls
48 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package practice9_dp;
import java.util.*;
import java.io.*;
public class Question4 {
// https://www.acmicpc.net/problem/1994
// 등차 수열
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N + 1];
// i, j 의 마지막 등차수열의 최대 길이 값
int[][] dy = new int[N + 1][N + 1];
for (int i = 1; i <= N; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(arr);
int answer = 0;
if(N == 1) {
System.out.print(1);
return;
}
for (int i = 1; i < N; i++) {
for (int j = i + 1; j <= N; j++) {
dy[i][j] = 2;
// 등차 값 arr[i] - ( arr[j] - arr[i] );
int pre = 2 * arr[i] - arr[j];
int k = 0;
for (k = i - 1; k >= 1; k--) {
if(arr[k] == pre) break;
}
dy[i][j] = Math.max(dy[i][j], dy[k][i] + 1);
answer = Math.max(answer, dy[i][j]);
}
}
System.out.println(answer);
}
}