(ProjectEuler) Sum Combinations

前端 未结 7 1587
忘了有多久
忘了有多久 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 09:01

    one approach is to think recursive function: find permutations of a numeric series drawn from the positive integers (duplicates allowed) that add up to 100

    • the zero is 1, i.e. for the number 1 there are zero solutions
    • the unit is 2, i.e for the number 2 there is only one solution

    another approach is to think generative function: start with the zero and find permutation series up to the target, keeping a map/hash or the intermediate values and counts

    you can iterate up from 1, or recurse down from 100; you'll get the same answer either way. At each point you could (for a naive solution) generate all permutations of the series of positive integers counting up to the target number minus 1, and count only those that add up to the target number

    good luck!

    0 讨论(0)
提交回复
热议问题