-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIS.java
More file actions
executable file
·33 lines (31 loc) · 823 Bytes
/
LIS.java
File metadata and controls
executable file
·33 lines (31 loc) · 823 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
package array;
/**
* Created by Administrator on 2018/3/28 0028.
*/
public class LIS {
public static int LIS(int arr[], int n) {
int []dp=new int[n+1];
for (int i = 1; i <= n; ++i)
dp[i] = 0;
int ans;
dp[1] = 1;
for (int i = 2; i <= n; ++i) {
ans = dp[i];
for (int j = 1; j < i; ++j) {
if (arr[i] > arr[j] && dp[j] > ans)
ans = dp[j];
}
dp[i] = ans + 1;
}
ans = 0;
for (int i = 1; i <= n; ++i) {
if (dp[i] > ans)
ans = dp[i];
}
return ans;
}
public static void main(String[] args) {
int [] array={1 ,7 , 3 , 5 , 9 , 4, 8};
int ans=LIS(array,7);
}
}