well as others posted some solutions too, here is a translation of the naive extension of the problem using Haskell and simple recursion:
combinations :: Int -> [Int] -> [[Int]]
combinations _ [] = [[]]
combinations w (x:xs)
| w >= x = [ x:ys | ys <- combinations (w-x) xs] ++ combinations w xs
| otherwise = combinations w xs
test-run
λ> combinations 7 [5,4,3,1,1]
[[5,1,1],[5,1],[5,1],[5],[4,3],[4,1,1],[4,1],[4,1],[4],[3,1,1],[3,1],[3,1],[3],[1,1],[1],[1],[]]
what's going on?
starting with 5 you have two choices: either you take it or not.
- if you take it you have limit 2 left and so you should recursively look for how many ways you can do this
- if not you still have limit 7 but only 1,1,3,4 to look for ....
the algorithm translates this into basic Haskell in a hopeful readable way - feel free to ask for details
remarks
I did not look at the performance at all - but it should be easy doing the same stuff you would do with the original problem (rewrite columns of the table, ...)