Created
August 30, 2010 07:30
-
-
Save dagoof/557132 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 <iostream> | |
using namespace std; | |
class memoize{ | |
public: | |
memoize(int); | |
double fib(int); | |
private: | |
double *memo; | |
int n; | |
}; | |
int main(){ | |
int n=1476; | |
memoize *thing=new memoize(n); | |
cout << thing->fib(n) << endl; | |
return 0; | |
} | |
memoize::memoize(int n){ | |
memo=new double[n+1]; | |
for(int i=0; i<n+1; i++){ | |
memo[i]='\0'; | |
} | |
} | |
double memoize::fib(int n){ | |
if(memo[n]!='\0'){ | |
return memo[n]; | |
} | |
else if(n==0 || n==1){ | |
memo[n]=n; | |
return n; | |
} | |
else{ | |
memo[n]=fib(n-1)+fib(n-2); | |
return memo[n]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment