Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _MIN_SUM = 100
- _MAX_SUM = 200
- _MIN_NUM = 1
- _MAX_NUM = 49
- _NUM_CHOICES = 6
- def f(n=_NUM_CHOICES, l=_MIN_NUM, s=0, cache={}):
- # Base case.
- if n == 0: return int(_MIN_SUM <= s <= _MAX_SUM)
- key = (n, l, s)
- result = cache.get(key)
- if result is None:
- # Induction.
- result = sum(f(n-1, l=i+1, s=s+i) for i in xrange(l, _MAX_NUM+1))
- cache[key] = result
- return result
- if __name__ == '__main__':
- print(f())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement