Monotonically incrementing maximum eldest son sequence time limit: 3000 MS | memory limit: 65535 kb difficulty: 4
-
Description
-
Returns the length of the longest incrementing sub-sequence of a string.
For example, the longest incremental sub-sequence of dabdbf is abdf and the length is 4.
-
Input
-
The first line has an integer of 0 <n <20, indicating that N strings are to be processed.
Next n rows, each line has a string, the length of the string will not exceed 10000
-
Output
-
Length of the longest incrementing sub-sequence of the output string
-
Sample Input
-
3aaaababcabklmncdefg
-
Sample output
-
137
-
The application of the basic idea of dynamic planning is controlled by an external loop, from local optimization to global optimization, and the local optimization is updated during the cycle process to achieve the end of the cycle, from local to global sublimation;
-
# Include <stdio. h> # include <string. h> # define max (A, B) A> B? A: B // calculate the maximum value # define max_len 10010 // The maximum supported sequence length int DP [max_len]; // Save the dynamic local solution char ch [max_len]; // Save the original data int main () {int T, <span style = "font-family: tahoma, Arial, sans-serif, simsun;"> Len; </span>
-
Int I, j; scanf ("% d", & T); While (t --) {int ans = 0; // scanf ("% s ", ch); Len = strlen (CH); for (I = 0; I <Len; I ++) // traverse each character {DP [I] = 1; // The minimum sequence length is 1for (j = 0; j <I; j ++) // For each I, traverse all characters before I {If (CH [J] <ch [I]) // if this character (CH [J]) is less than the current character (CH [I]) it indicates that DP [I] = max (DP [I], DP [J] + 1);} ans = max (ANS, DP [I]); // obtain the current global optimum (relative to I)} printf ("% d \ n", ANS);} return 0 ;}
Monotonically incrementing longest son Sequence