Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Function
- import Data.List
- combinations :: Int -> [a] -> [[a]]
- combinations 0 _ = [ [] ]
- combinations n xs = [ y:ys | y:xs' <- tails xs
- , ys <- combinations (n-1) xs']
- names = ["clock", "painting", "radio", "vase", "book", "computer"]
- vals = [175, 90, 20, 50, 10, 200]
- weights = [10, 9, 4, 2, 1, 20]
- goods = [(names !! i,vals !! i,weights !! i) | i<-[0..5]]
- combs = foldl1 (++) [combinations i goods | i<-[1..6]]
- less = filter (\xs -> sum [w|(_,_,w)<-xs] <= 20) combs
- ans = maximumBy (on compare (\r -> sum [v|(_,v,_)<-r])) less
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement