-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedRaiment.java
More file actions
45 lines (40 loc) · 1013 Bytes
/
RedRaiment.java
File metadata and controls
45 lines (40 loc) · 1013 Bytes
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
package com.hw;
import java.util.Scanner;
/**
* @author: yhl
* @DateTime: 2020/5/28 11:38
* @Description:
*/
public class RedRaiment {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int nums = sc.nextInt();
int[] a = new int[nums];
for (int i = 0; i < nums; i++) {
a[i] = sc.nextInt();
}
System.out.println(getMaxStep(a));
}
}
//6
//2 5 1 5 4 5
public static int getMaxStep(int[] a) {
int[] dp = new int[a.length];
for (int i = 0; i < a.length; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (a[i] > a[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}
int max = 0;
for (int value : dp) {
if (value > max) {
max = value;
}
}
return max;
}
}