Created
April 6, 2016 05:24
-
-
Save cameronmoreau/b925bdcc284f8aadb39128876fa4c77b to your computer and use it in GitHub Desktop.
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
#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