Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
import Data.Array
|
||||
|
||||
-- snipped the item list; use the one from above
|
||||
knapsack items cap = (solu items) ! cap where
|
||||
solu = foldr f (listArray (0,cap) (repeat (0,[])))
|
||||
f (name,w,v,cnt) ss = listArray (0,cap) $ map optimal [0..] where
|
||||
optimal ww = maximum $ (ss!ww):[prepend (v*i,(name,i)) (ss!(ww - i*w))
|
||||
| i <- [1..cnt], i*w < ww]
|
||||
prepend (x,n) (y,s) = (x+y,n:s)
|
||||
|
||||
main = do print $ knapsack inv 400
|
||||
Loading…
Add table
Add a link
Reference in a new issue