Problem 81
コンテンツ
http://projecteuler.net/index.php?section=problems&id=81
ものすごくそのままなDP
import Data.Array.IArray import Control.Monad root ::Array (Int,Int) Integer->Array (Int,Int) Integer root cost = r where r = listArray b b = bounds cost c (i,j) = cost!(i,j) + f [r!ix|ix<-[(i+1,j),(i,j+1)],inRange b ix] f [] = f [a] = a f [a,b] = min a b mkArray ::String->Array (Int,Int) Integer mkArray ws= listArray ((1,1),(m,m)) ws' where ws'=concat.map (read.g).lines$ws m = floor.sqrt.fromIntegral.length$ws' g x = "["++x++"]" main = liftM((!(1,1)).root.mkArray).readFile$"matrix.txt"
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)