函数式编程
这是我在Python中的解决方案(指数时间):q = { 1: [[1]] }def decompose(n): try: return q[n] except: pass result = [[n]] for i in range(1, n): a = n-i R = decompose(i) for r in R: if r[0] <= a: result.append([a] + r) q[n] = result return result >>> decompose(5)[[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]