Http://acm.pku.edu.cn/JudgeOnline/problem? Id = 1887
The topic description is complex. In fact, it is to find the longest descent subsequence, which is also a typical topic of dynamic planning. There are two algorithms for this type of problem: T (o) = O (N ^ 2), and T (o) = O (nlogn). Here we use the first one, the second type is described in the 1631 bridging signals solution report.
Create a one-dimensional array num_array [J], max_array [], num_array [J] to indicate the sequence elements, max_array [I] indicates the longest descent subsequence in the sequence ending with element I, initialized as 1. For a max_array [I], traverse each element J, if num_array [J]> num_array [I] And max_array [J]> = max_array [I], 1 is required for max_array [J], so the recurrence formula is:
If (num_array [I] <= num_array [J] & max_array [I] <= max_array [J])
Max_array [I] ++;
The largest max_array [I] is the maximum number of dropped subsequences. Code of the key part of Java:
For (INT I = 1; I <length; I ++ ){
For (Int J = 0; j <I; j ++ ){
If (num_array [I] <= num_array [J] & max_array [I] <= max_array [J])
Max_array [I] ++;
}
Max_value = (max_array [I]> max_value )? Max_array [I]: max_value;
}
Max_value is the final result.
Code with detailed comments can be obtained at http://download.csdn.net/user/china8848/