Algorithm design job LIS (maximum incrementum sequence)

xiaoxiao2021-03-06  48

/ * Function Description: Given a non-negative integer array, find the longest increasing subsequence Author: hfjiang Completion Date: 2005-3-13 * / # include using namespace std; #define GT 1000 # define LT. -1000 # Define EQ 5000Int Max (Const Int I, Const Int J, Const Int T [6], Const Int size); int main () {// int A [6] = {0, 5, 4 , 2, 1, 3}; int A [6] = {0, 1, 2, 3, 4, 5};

// Do not consider the case of the same elements in the array, actually super simple

/ / More, change 6. // int size = sizeof (a) / 4; int size = 6; int Ti [6] [6]; for (int i = 0; i a [j]) t [i] [j] = gt; if (a [i] == a [j]) t [ I] [j] = EQ; IF (a [i]

// Dynamic Programing for (i = 0; i = 0; i -) {for INT j = i 1; j

} int MAX (Const Int I, Const Int J, Const Int T [6] [6], Const Int Size {/ * Return The max value of t [i] [j .... size-1]; * / Int max = t [i] [j]; for (int K = J 1; k

Program design ideas:

D.P

1. First establish a relational table: size prejudice relationship. Only less than the relationship can go (upper triangle matrix). The diagonal is initialized to 1.

2. Retrospective: From the top triangle matrix from bottom to top the maximum.

3. The above program is not given a child sequence: Simply find the maximum element of each row in the final matrix, which is the element in LIS.

4. Eventually there may be multiple paths: because there may be multiple LIS.

D.P

1. First establish a relational table: size prejudice relationship. Only less than the relationship can go (upper triangle matrix). The diagonal is initialized to 1.

2. Retrospective: From the top triangle matrix from bottom to top the maximum.

3. The above program is not given a child sequence: Simply find the maximum element of each row in the final matrix, which is the element in LIS.

4. Eventually there may be multiple paths: because there may be multiple LIS.

D.P

1. First establish a relational table: size prejudice relationship. Only less than the relationship can go (upper triangle matrix). The diagonal is initialized to 1.

2. Retrospective: From the top triangle matrix from bottom to top the maximum.

3. The above program is not given a child sequence: Simply find the maximum element of each row in the final matrix, which is the element in LIS.

4. Eventually there may be multiple paths: because there may be multiple LIS.

D.P

1. First establish a relational table: size prejudice relationship. Only less than the relationship can go (upper triangle matrix). The diagonal is initialized to 1.

2. Retrospective: From the top triangle matrix from bottom to top the maximum.

3. The above program is not given a child sequence: Simply find the maximum element of each row in the final matrix, which is the element in LIS.

4. Eventually there may be multiple paths: because there may be multiple LIS.

PLZ Enjoy!


New Post(0)