Created
March 19, 2020 18:25
-
-
Save smrt28/791cfd3993f76cc23b7ccdf4eaa87fe2 to your computer and use it in GitHub Desktop.
problem
This file contains hidden or 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
| #include <iostream> | |
| #include <string.h> | |
| #include <stdint.h> | |
| static const int X = 100; | |
| int64_t cache[X]; | |
| int64_t fn(int64_t a) { | |
| if (cache[a] > 0) return cache[a]; | |
| if (a == 0) return 0; | |
| int64_t res = 0; | |
| for (int64_t i = 1; i <= a/2; ++i) { | |
| int64_t tmp = fn(i) * fn(a - i); | |
| if (tmp > res) res = tmp; | |
| } | |
| if (res < a) return a; | |
| cache[a] = res; | |
| return res; | |
| } | |
| int main() { | |
| memset(cache, 0, sizeof(cache)); | |
| for(int64_t i = 0; i < X; ++i) { | |
| std::cout << fn(i) << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment