Created
August 12, 2011 23:27
-
-
Save gorlum0/1143218 to your computer and use it in GitHub Desktop.
spoj - Coins.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""(c) gorlum0 [at] gmail.com""" | |
from sys import stdin | |
def exchange(n, _cache = {0: 0}): | |
if not _cache.has_key(n): | |
v = exchange(n//2) + exchange(n//3) + exchange(n//4) | |
_cache[n] = max(n, v) | |
return _cache[n] | |
def main(): | |
for n in map(int, stdin): | |
print exchange(n) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment