Add tags

Add tags to the following comment
comb の方にも和の制約を入れたら手元のマシンで
magic 5 のケースが4倍速になりました。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
comb :: Int -> Int -> [Int] -> [([Int],[Int])]
comb s _ xs | s < 0 = []
comb s 0 xs | s == 0    = [([],xs)]
            | otherwise = []
comb _ _ [] = []
comb s k (x:xs) = [ (x:ys,zs) | (ys,zs) <- comb (s-x) (k-1) xs ]
                ++[ (ys,x:zs) | (ys,zs) <- comb s     k     xs ]

comb' :: Int -> Int -> [Int] -> [([Int],[Int])]
comb' s 0 xs | s == 0    = [([],xs)]
             | otherwise = []
comb' _ _ []             = []
comb' s k (x:xs) = [ (x:ys,zs) | (ys,zs) <- comb (s-x) (k-1) xs ]

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...