Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import Control.Applicative
  2. import Control.Monad
  3. import Data.Bits
  4.  
  5. rule :: [Int] -> (Int, Int)
  6. rule x = (x !! 0, x !! 1)
  7.  
  8. hasEdge :: Int -> Int -> [(Int, Int)] -> Bool
  9. hasEdge s v list = foldr edge False list
  10. where edge t b = b || (fst t) == v && testBit s (snd t)
  11.  
  12. func :: Int -> Int -> [(Int, Int)] -> Int
  13. func s n t = if s == 1 then 1 else sum $ map (\a -> if (testBit s a) && not (hasEdge s a t) then func (clearBit s a) n t else 0) [1..n]
  14.  
  15. main :: IO ()
  16. main = do
  17. [n, m] <- map read . words <$> getLine
  18. t <- replicateM m $ rule . map read . words <$> getLine
  19. let b = foldl (setBit) (bit 0) [1..n] :: Int
  20.  
  21. putStrLn $ show $ func b n t
  22.  
  23. return ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement