File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments