Efficient table for Dynamic Programming in Haskell

后端 未结 5 1666
青春惊慌失措
青春惊慌失措 2021-01-31 06:03

I\'ve coded up the 0-1 Knapsack problem in Haskell. I\'m fairly proud about the laziness and level of generality achieved so far.

I start by providing functions for crea

5条回答
  •  既然无缘
    2021-01-31 06:23

    Why won't you use Data.Map putting the other Data.Map into it? As far as I know it's quite fast. It wouldn't be lazy though.

    More than that, you can implement Ord typeclass for you data

    data Index = Index Int Int
    

    and put a two dimensional index directly as a key. You can achieve laziness by generating this map as a list and then just use

    fromList [(Index 0 0, value11), (Index 0 1, value12), ...] 
    

提交回复
热议问题