Each positive integer n has 2^(n−1) distinct compositions. what If I want the number of composition which is only have specific number which is in my list:
for example composition of 4 is
4
3 1
1 3
2 2
2 1 1
1 2 1
1 1 2
1 1 1 1
but if I want the number of composition of 4 which it has only 1 and 2, How could I calculate the NUMBER of distinct compositions?
2 2
2 1 1
1 2 1
1 1 2
1 1 1 1
Edited: Here Haskell code which calculate the number, But I think It takes too long even IF I add memorization for Number 70
main :: IO ()
main = do
putStrLn "Enter the integer number"
num' <- getLine
let num = read num' :: Int
putStr ""
let result= composition num
let len=length result
print len
--print result
composition 0 = [[]]
composition n = [x:rest | x <- [1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000],x<=n ,rest <- composition (n-x)]