(ProjectEuler) Sum Combinations

前端 未结 7 1634
忘了有多久
忘了有多久 2020-12-30 08:09

From ProjectEuler.net:

Prob 76: How many different ways can one hundred be written as a sum of at least two positive integers?

I have no ide

7条回答
  •  长情又很酷
    2020-12-30 08:45

    Partition Numbers (or Partition Functions) are the key to this one.

    Problems like these are usually easier if you start at the bottom and work your way up to see if you can detect any patterns.

    • P(1) = 1 = {1}
    • P(2) = 2 = {[2], [1 + 1]}
    • P(3) = 3 = {[3], [2 + 1], [1 + 1 + 1]}
    • P(4) = 5 = {[4], [3 + 1], [2 + 2], [2 + 1 + 1], [1 + 1 + 1 + 1]}
    • P(5) = 7 ...
    • P(6) = 11 ...
    • P(7) = 15 ...
    • P(8) = 22 ...
    • P(9) = 30 ...

    Hint: See if you can build P(N) up from some combination of the results prior to P(N).

提交回复
热议问题