Longest increasing sequence of image analysis problems

I, entitled:

Find a longest sequence of integers of n integers incremental sequence. Increasing subsequence sequence may be an integer number of noncontiguous sequence arrayed in the order according to the original sequence. Longest increasing increments its sequence is the longest sequence length.

 

Second, the problem-solving ideas:

The results create a string that holds the longest sequence.

For each number of the original sequence, can be selected if the condition packed with or without, if the condition is not placed.

By thinking recursive, all the possible outcomes may soon be derived sequence, and then by determining its size, to elect the greatest sequence.

On the map analysis:

  The black line represents the next into line with a number of conditions, not into the yellow line indicates the result in the green ellipse is the last possible sequence obtained (FIG upper leg 123 is not drawn to give complete).

  To 34123, for example, may choose to begin a sequence of answers is not placed into the 3 or 3, 3 can be put into the selected 4 4 or into (the number must be greater than the number placed before a loaded), keep it that way until the last read original sequence number or no longer find qualified number, and finally by comparison, the longest sequence to get the answer sequence.

 

Third, the implementation code

. 1  public  class Long_list {
 2      public String List ( char S []) {
 . 3          String T = "" ;
 . 4          return L (S, T, 0 );
 . 5      }
 . 6  
. 7      Private String L ( char S [], String T, int LO) { // start to finish determination every qualified not loaded into the case 
. 8          IF (LO> s.length -. 1) { // the last one has been completed is determined outlet. 1 
. 9              return T;
 10          }
 . 11          String K = "" ;
 12 is          for (int i = lo; i < s.length; i++) {
13             if ((t.length() == 0) || ((t.length() - 1 >= 0) && t.charAt(t.length() - 1) < s[i])) {
14                 k = t + s[i];// 连接
15                 break;
16             }
17         }
18         return max(l(s, t, lo + 1), l(s, k, lo + 1));
19     }
20 
21     private String max(String l, String l2) {
22         return l.length() >= l2.length() ? l : l2;
23     }
24 
25     public static void main(String[] args) {
26         char c[] = { '3', '1', '4', '2', '3' };
27         Long_list ll = new Long_list();
28         System.out.println(ll.list(c));
29     }
30 }

 

Guess you like

Origin www.cnblogs.com/Unicron/p/11574579.html