You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO import Prelude -- Nice memoizer from StackOverflow memo :: (Int -> Int -> a) -> [[a]] memo f = map (\x -> map (f x) [0..]) [0..] pascstore :: [[Integer]] pascstore = memo pascal fastpasc :: Int -> Int -> Integer fastpasc x y = pascstore !! x !! y -- Basic Pascal Triangle Recursion pascal :: Int -> Int -> Integer pascal n 0 = 1 pascal 0 k = 1 pascal n k = (fastpasc n (k-1)) + (fastpasc (n-1) k) main :: IO () main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n = (map (read :: String -> Int) . words) n_temp let m = max (n !! 0) (n !! 1) let k = min (n !! 0) (n !! 1) let routes = pascal m k print(routes `mod` 1000000007)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #15: Lattice paths
You are viewing a single comment's thread. Return to all comments →
Haskell