Created
March 20, 2018 06:43
-
-
Save MuhammadJahidHasan/90d57ac35caad0e2493c39bf69459f46 to your computer and use it in GitHub Desktop.
Fibonacci with dynamic program in bottom up approach
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; | |
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