Skip to content

Instantly share code, notes, and snippets.

@cameronmoreau
Created April 6, 2016 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronmoreau/b925bdcc284f8aadb39128876fa4c77b to your computer and use it in GitHub Desktop.
Save cameronmoreau/b925bdcc284f8aadb39128876fa4c77b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int max(int x, int y) {
if(x > y) return x;
return y;
}
int func_aux(int N, int sols[]) {
if(N <= 1) return 1;
if(sols[N] != -1) return sols[N];
printf("Calculating %d...\n", N);
int res = func_aux(N-1, sols);
sols[N] = res;
return res;
}
int func(int N) {
int x, y;
int sols[N+1];
for(x = 0; x < N+1; x++) sols[x] = -1;
x = func_aux(N-1, sols);
y = func_aux(N-2, sols);
return max(2*y, 3+x);
}
int main() {
int i = func(10);
printf("%d\n", i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment