Skip to content

Instantly share code, notes, and snippets.

@dagoof
Created August 30, 2010 07:30
Show Gist options
  • Save dagoof/557132 to your computer and use it in GitHub Desktop.
Save dagoof/557132 to your computer and use it in GitHub Desktop.
#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