Algorithm
In the algorithm, I came up with work using a list of ordered pairs. The steam is first ordered by one element, then the second.
We keep lists of pairs, where each new pair:
- added to the end of the highest list if it can fit after the last item
- , , ,
- , .
- , .
- n -th ( ), .
- n, k, n, , n, - 2. - i, k, 2 i. k .
.
foreach ordered pair
maximumIndex <- 0
maximumList <- null
foreach list
highest, length <- FindLongestPath(list, pair)
if highest > maximumHeight
maximumHeight<- highest
maximumIndex <- lenght
maximumList <- list
if maximumIndex = 0
lists.add(new list{pair});
else if maximumIndex < maximumList.Length
lists.add(new list{maximumList[0..maximumIndex - 1] + pair});
else
list.add{pair};
FindLongestPath , , . (for , ), O (N ^ 2) .
, O (N log N), , N <= 100 .
, # pastebin: http://pastebin.com/3vLn343j
"Input.txt", , , ( Visual Studio , " " - , ").