Skip links
Jump to the content
Jump to the menu
Main content
Nieuw bericht
Nieuw bericht
Naam
*
Bericht
*
[quote=Samsam]I think I came up with basically the same<a href="http://jljwtilyvv.com"> aigrolthm</a> as hasan, but it doesn't require preprocessing for range max queries, and maybe it will be simpler to understand (or not).The idea is to maintain subarrays which are multipermutations, not necessarily maximal - which I'll call "green" subarrays - and subarrays surrounding each green one which must be contained in any larger multipermutation - I'll call these "yellow" subarrays. Keep growing these (occasionally turning yellow subarrays green when there is an actual multipermutation) until the whole array is covered either yellow or green, and then the largest green one is the answer.Call the array A with entries A[1]..A[n].I'll first present the case where there is only one "1" in the array. Note that any multipermutation must contain this "1", and also that it is itself a length-1 multipermutation. Say this "1" occurs at index k in the array. Then, for i=2..n, store the following:-L[i], the largest integer j<k such that A[j]=i-LM[i] := max(A[L[i]..k])-R[i], the smallest integer j>k such that A[j]=i-RM[i] := max(A[k..R[i]])Clearly, these four arrays can be computed in linear time in a single pass left and right from index k.We will maintain a single "green" subarray, which is itself a subarray of a single "yellow" subarray. Initially, these are both just the single "1" at A[k]. Also maintain:-The largest integer in the yellow subarray, initially 1; call it a.-The smallest integer not present in the yellow subarray, initially 2; call it bNow repeat the following steps:-(Grow yellow subarray) Compare LM[b] and RM[b]. If LM[b] is smaller, then grow the yellow subarray to the left to index L[b] - which must not already be in the yellow subarray by the definition of b. Update a and b as each new element is added (updating b in constant time can be done with some more bookkeeping). If RM[b] is smaller, do the opposite. If LM[b]=RM[b], then grow in both directions.-(Check for multipermutation) If b>a, change the whole yellow subarray to green and expand in both directions to include all adjacent integers a.This process terminates after at most n steps (any number larger than n can't be part of a multipermutation), and the amortized cost over all steps is O(n), since the yellow array only grows. At the end, the green array is the largest multipermutation.For the more general case (more than one "1" in the array), we start initially with each "1" being its own green (and yellow) array, and grow them all simultaneously, merging the yellow and then green arrays when they meet. Constructing the arrays becomes a bit trickier to do in linear time, but is possible by using the fact that any multipermutation on a sub-interval of length m can only contain integers m.[/quote]
CAPTCHA
*
V
erzenden
A
nnuleer
Main menu
Weblog
Cognition
Architectures
Architectures
ACT-R
H-CogAff
IDA
MicroPSI
Links
Pictures
Vakantie Duitsland (2011)
Openluchtmuseum (2007)
Huwelijk (2004)