Home >Web Front-end >HTML Tutorial >Codeforces Round #267 (Div. 2) E Alex and Complicated Task_html/css_WEB-ITnose
A very good thinking question, greedy
The main idea of the question: Given n numbers, you need to find the longest subsequence so that the 4k-4k 3 items of this subsequence are The form of a,b,a,b (numbered from 0).
Awesome greed, but my thinking ability is still not good...
I can think of some ideas, but I can’t write down the code...
Reference http://www.cnblogs.com/shiina-mashiro/p/3981944.html
Idea:
1. To deal with the situation where four numbers are equal, just output the four numbers directly - --- Use map for the number of times the record number appears, so there is no need for discretization (on the Internet, it is said that when querying map, logn, discretization requires sorting, nlogn, when large numbers need to be mapped into decimals, doesn't it need to be discretized? . . )
2. The case of ABAB
First of all, we must understand that two pairs of numbers must be adjacent to form ABAB. This was not considered at first. I thought it would require an O(n^2) algorithm, so I didn’t dare to write it.
Then give two adjacent logarithmic analysis ideas (a, b) (c, d).
d>b Obviously, because d is the number currently read, a, b, c, are the numbers read previously
Then according to the relationship between c and a, b, the following situations can be divided: