18/11/17 09:45:00.71 u+BaxmkL.net
>>475
やった。
順列使わないで三番目が6個になった!
Haskell
main = mapM_ print $ map mapbox (slist list)
slist xs = map (\(x,y) -> (x, qsort y)) xs
mapbox (x,y) = (x,length (box x [] [] y))
box _ [] [] [] = [[]]
box _ ns [] [] = [ns]
box c ns ys [x] | c >= sum (x:ns) = box c (x:ns) [] (reverse ys)
box c ns ys [x] | c < sum (x:ns) = [ns] ++ box c [] [] (reverse (x:ys))
box c ns ys (x:xs) | c >= sum (x:ns) = box c (x:ns) ys xs
box c ns ys (x:xs) | c < sum (x:ns) && c >= sum ((last xs):ns) = box c ns (x:ys) xs
box c ns ys (x:xs) | c < sum (x:ns) && c < sum ((last xs):ns) = [ns] ++ box c [] [] (reverse ys ++ (x:xs))
qsort [] = []
qsort (x:xs) = large ++ [x] ++ small
where
small = qsort [a|a <- xs,a <= x]
large = qsort [a|a <- xs,a > x]
list = [(30,[8,5,10,6,4,5,8,5,9,6,9]),
(120,[33,61,58,41,50,21,60,64]),
(120,[33,61,58,41,50,21,60,64,23,45,67,78,89])]