Haskell 对一些整数分区进行编号

Haskell 对一些整数分区进行编号,haskell,combinatorics,Haskell,Combinatorics,这些树表示n的整数分区提示:n的子树包含多少项?只是想知道。。。该算法可以应用于任何语言,因此可以将语言不可知添加为标记以及算法标记。我知道很多熟练的人都遵循算法标签。@WillemVanOnsem对不起,我没有看到一个简单的公式。但是我现在在医院(没有什么严重的),身体状况不好,无法集中精力。。。 1 2 3 4 5 | / \ / \ | |

这些树表示
n的整数分区提示:
n
的子树包含多少项?只是想知道。。。该算法可以应用于任何语言,因此可以将语言不可知添加为标记以及算法标记。我知道很多熟练的人都遵循算法标签。@WillemVanOnsem对不起,我没有看到一个简单的公式。但是我现在在医院(没有什么严重的),身体状况不好,无法集中精力。。。
1            2                 3          4      5
|          /   \             /   \        |
|         /     \           /     \       |
|        /       \         /       \      |
1,1     2,1      2,2     3,1      3,2    4,1
|        |        |       |
|        |        |       |
|        |        |       |
1,1,1   2,1,1    2,2,1  3,1,1
1 2 3 4 5 
6 7 8 9 10 11
12 13 14 15
dico' :: Int -> Int -> Seq (Maybe Int)
dico' m n = go 1 S.empty
  where
  go :: Int -> Seq (Maybe Int) -> Seq (Maybe Int)
  go k d'
    | k == n-1 = d'
    | otherwise = go (k+1) (inner 0 [0] [m] [m] 0 d')
      where
      inner :: Int -> [Int] -> [Int] -> [Int] -> Int -> Seq (Maybe Int) -> Seq (Maybe Int)
      inner i a b c end d
        | i >= length a = d -- what is the terminating condition here ?
        | otherwise = if b!!i > 0
          then let l = min (b!!i) (c!!i) in
          let dd = d |> (Just $ end+1) in
          inner (i+1) (a ++ [end + 1 .. end + l]) (b ++ map (\x -> b!!i - x) [1 .. l]) (c ++ [1 .. l]) (end + l) dd
          else inner (i+1) a b c end (d |> Nothing)
> dico' 5 3
fromList [Just 1,Just 6,Just 7,Just 9,Just 11,Nothing,Just 12,Just 13,Just 14,Just 15,Nothing,Nothing,Just 16,Just 17,Nothing,Nothing,Just 18,Nothing,Nothing]
a008284_tabl :: [[Int]]
a008284_tabl = [1] : f [[1]]
  where
  f xss = ys : f (ys : xss)
    where
    ys = map sum (zipWith take [1..] xss) ++ [1]

_P :: Int -> Int -> Int
_P m n = sum (concatMap (take (min m n)) (take m a008284_tabl))

dico' :: Int -> Int -> Seq (Maybe Int)
dico' m n = go 1 S.empty
  where
  pmn = Just $ Just $ _P m n
  go :: Int -> Seq (Maybe Int) -> Seq (Maybe Int)
  go k d'
    | k == n-1 = d'
    | otherwise = go (k+1) (inner 0 [0] [m] [m] 0 d')
      where
      inner :: Int -> [Int] -> [Int] -> [Int] -> Int -> Seq (Maybe Int)
            -> Seq (Maybe Int)
      inner i a b c end d
        | S.lookup (S.length d - 1) d == pmn = d
        | otherwise = let bi = b!!i in
          if bi > 0
            then let l = min bi (c!!i) in
              let dd = d |> (Just $ end+1) in
              let range1l = [1 .. l] in
              inner (i+1) (a ++ [end + 1 .. end + l])
                          (b ++ map (\x -> bi - x) range1l)
                          (c ++ range1l) (end + l) dd
            else inner (i+1) a b c end (d |> Nothing)


> dico' 5 3
fromList [Just 1,Just 6,Just 7,Just 9,Just 11,Nothing,Just 12,Just 13,Just 14,Just 15]
> dico' 10 7
fromList [Just 1,Just 11,Just 12,Just 14,Just 17,Just 21,Just 26,Just 30,Just 33,Just 35,Nothing,Just 36,Just 37,Just 38,Just 40,Just 41,Just 43,Just 46,Just 47,Just 49,Just 52,Just 54,Just 55,Just 57,Just 59,Nothing,Just 60,Just 61,Just 63,Nothing,Just 64,Just 65,Nothing,Just 66,Nothing,Nothing,Just 67,Just 68,Just 69,Just 70,Just 72,Just 73,Just 74,Just 76,Just 77,Just 79,Just 80,Just 81,Just 82,Just 84,Just 85,Nothing,Just 86,Nothing,Just 87,Just 88,Just 89,Just 90,Nothing,Nothing,Just 91,Just 92,Nothing,Nothing,Just 93,Nothing,Nothing,Just 94,Just 95,Just 96,Just 97,Just 98,Just 100,Just 101,Just 102,Just 103,Just 104,Just 105,Nothing,Nothing,Just 106,Just 107,Just 108,Nothing,Just 109,Nothing,Nothing,Just 110,Just 111,Nothing,Nothing,Just 112,Nothing,Nothing,Just 113,Just 114,Just 115,Just 116,Just 117,Nothing,Just 118,Just 119,Just 120,Nothing,Just 121,Nothing,Just 122,Just 123,Nothing,Nothing,Just 124,Nothing,Nothing,Just 125,Just 126,Just 127,Just 128,Nothing,Just 129,Just 130,Nothing,Nothing,Just 131]