byteland.cpp

#include <map> #include <stdio.h> #include <memory.h> #include <algorithm> typedef long long ity; std::map<ity, ity> profit_cache; inline ity get_profitable_amt(ity n) { if (n == 0) return 0; //base ity profit = profit_cache[n]; if (profit == 0) { profit = std::max(n, get_profitable_amt(n / 2) + get_profitable_amt(n / 3) + get_profitable_amt(n / 4)); profit_cache[n] = profit; } return profit; } inline void solve() { ity n; while(scanf("%lld", &n) != EOF) { printf("%lld\n", get_profitable_amt(n)); } } int main() { solve(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.