Skip to content

Instantly share code, notes, and snippets.

@smrt28
Created March 19, 2020 18:25
Show Gist options
  • Select an option

  • Save smrt28/791cfd3993f76cc23b7ccdf4eaa87fe2 to your computer and use it in GitHub Desktop.

Select an option

Save smrt28/791cfd3993f76cc23b7ccdf4eaa87fe2 to your computer and use it in GitHub Desktop.
problem
#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