How to find maximum product ascending sub sequence of size k in an (non negative) integer array of size n. I did not find any good solution. The sub sequence need not be contiguous. For ex: 3,7,8 in 10,1,3,9,7,8,5 for size 3.
Try reducing to a problem you've seen before.
In Haskell, you could do this, although it may not be very fast for large n:
import Data.List (maximumBy, sort, subsequences)
maxSubProduct k =
maximumBy (\a b -> compare (foldr (*) 1 a) (foldr (*) 1 b))
. filter (\x -> x == sort x)
. filter ((==k) . length)
. subsequences
OUTPUT:
*Main> maxSubProduct 3 [10,1,3,9,7,8,5]
[3,7,8]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.