-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from abhijeetaman007/master
Solution to DP problem Climbing Stairs added
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
Program's_Contributed_By_Contributors/Dynamic Programming/ClimbingStairs.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int climbStairs(int n) | ||
{ | ||
int dp[n + 2]; | ||
dp[0] = 0; | ||
dp[1] = 1; | ||
dp[2] = 2; | ||
for (int i = 3; i <= n; i++) | ||
{ | ||
dp[i] = dp[i - 1] + dp[i - 2]; | ||
} | ||
return dp[n]; | ||
} | ||
|
||
int main(int n) | ||
{ | ||
int n; | ||
//Enter Number of Stairs | ||
cin>>n; | ||
int ans=climbStairs(n); | ||
cout<<ans<<endl; | ||
} |