The simple realization of the _java Java of the longest increment sub-sequence of LIS

Source: Internet
Author: User

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]&amp ;& (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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.