Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MuhammadJahidHasan/90d57ac35caad0e2493c39bf69459f46 to your computer and use it in GitHub Desktop.
Save MuhammadJahidHasan/90d57ac35caad0e2493c39bf69459f46 to your computer and use it in GitHub Desktop.
Fibonacci with dynamic program in bottom up approach
#include <iostream>
using namespace std;
long long dp[1000];
long long fib(int n){
if(n==1 || n==2) return 1;
if(dp[n]!=-1) return dp[n];
return dp[n]=fib(n-1)+fib(n-2);
}
int main()
{
for(int i=0;i<1000;i++){
dp[i]=-1;
}
int m;
cin>>m;
cout<<fib(m);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment