Question address: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 2136.
The typical DP is divided into the following subproblem: The record length [k] is, And the AK is the maximum length of the ascending suborder of the last element. When this value is obtained, you only need to retrieve the smaller number before this number to see how long it is and get the largest length.
M records the length of the previous subproblem and is initialized to 0.
The result of this implementation is that, with length [0], we can find length [1], and then we can find length [2 ]....... In this way, the problem of O (2 ^ N) becomes O (N ^ 2 ).
The final result is the smallest of all lengths.
# Include <iostream> using namespace STD; int main () {int size; CIN> size; For (int l = 0; L <size; l ++) {int N; CIN> N; int * P = new int [N]; int * length = new int [N]; for (INT I = 0; I <N; I ++) CIN> P [I]; length [0] = 1; for (INT I = 1; I <n; I ++) {int m = 0; // represents the previous number length [I] = 1; for (Int J = 0; j <I; j ++) {If (P [J] <p [I]) {If (length [J]> m) {length [I] = length [J] + 1; M = length [J] ;}}} int max = 1; for (INT I = 0; I <n; I ++) if (length [I]> MAX) max = length [I]; cout <max <Endl; If (L <size-1) cout <Endl ;}}