java - Longest Convex Subsequence -


note, looked @ solution: longest convex subsequence in array

i've looked @ solution above fail understand it. know property convex subsequence is:

c[i] < (c[i-1] + c[i+1]) / 2 

so given input of: 2082 0 24719 1 383 4 20029 9 3781 16

the solution be: 2082 0 1 4 9 16

now, solution proposing o(n3)

public static int max(int... i){     int max = 0;     for(int n : i){         if(n > max)             max = n;     }     return max; }  public static void main(string[] args) {     scanner in = new scanner(system.in);     int n = in.nextint();      int[] arr = new int[n];     for(int = 0; < n; ++i)         arr[i] = in.nextint();      int[][][] lcs = new int[n][n][n];     for(int = 0; < n; i++){         (int j = 0; j < n; j++) {             (int k = 0; k < n; k++) {                 lcs[i][j][k] = 0;             }         }      }     for(int = 0; < arr.length-2; ++i){         for(int j=1; j < arr.length-1;++j){             for(int k = 2; k < arr.length; ++k){                 if(arr[j] < (arr[i]+arr[k])/2){                      lcs[i][j][k] = max(lcs[i][j][k], 1+ lcs[i][j][k-1]);                 }             }         }     }     int max = 0;     for(int = 0; < n; ++i) {         (int j = 0; j < n; j++) {             (int k = 0; k < n; k++) {                 if(lcs[i][j][k] > max)                     max = lcs[i][j][k];             }         }      }     system.out.println(max); } 

i understand naive feel on right track, i'm not sure why keep getting sequence of 8 answer. appreciated.


Comments

  1. Java - Longest Convex Subsequence - >>>>> Download Now

    >>>>> Download Full

    Java - Longest Convex Subsequence - >>>>> Download LINK

    >>>>> Download Now

    Java - Longest Convex Subsequence - >>>>> Download Full

    >>>>> Download LINK hh

    ReplyDelete

Post a Comment

Popular posts from this blog

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -