Today encountered a search for the longest increment subsequence problem, after looking at the attempt to use Java to achieve a bit, about what is the longest increment subsequence, here is not to repeat, you can Baidu or Google, the following is the implementation of the Code:
Description: This code implements the function is
(1) Randomly generate an array of 10 elements, and then output its longest incrementing subsequence
(2) The length of the maximum increment subsequence that the output ends with one of the elements
The specific implementation of the ideas in the comments have been detailed, relatively simple, here will not repeat
Import Java.util.Arrays;
Import Java.util.Random;
public class LIS {public static void main (string[] args) {System.out.println ("Generating a random array ...");
Lis lis=new lis ();
Int[] Oldarray=lis.randomarray ();
for (int i = 0; i < oldarray.length i++) {System.out.print (oldarray[i]+ "");
} System.out.println ();
System.out.println ("Length of the longest ascending subsequence is");
Lis.lisget (Oldarray);
Public int[] Randomarray () {Random random=new Random ();
Int[] Randomarray=new int[10];
for (int i = 0; i < i++) {Randomarray[i]=random.nextint (10);
return randomarray; The public void Lisget (int[] arrayl) {int[] lislength=new int[arrayl.length];//is used to record the length of the longest increment sequence for the current element as the largest element for ( int i = 0; i < arrayl.length;
i++) {//initialization of lislength[i]=1;
int max=1; for (int i = 1; i < Arrayl.length. i++) {for (int j = 0; J <i; J +) {if Arrayl[j]<arrayl[i]& ;& (lislength[j]+1) >Lislength[i]) {lislength[i]=lislength[j]+1;
} if (Max<lislength[i]) {//Gets the length of the current longest ascending sequence and the position of the last element of the subsequence max=lislength[i];
}} System.out.println (max); System.out.println ("The longest increment subsequence of the end of the first element:" +arrays.tostring (Lislength)); Output Array}}
The above is a small series for everyone to bring the LIS the longest increment sequence of the Java simple implementation of all the content, I hope to help you, a lot of support cloud Habitat Community ~