-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnStep.cpp
More file actions
30 lines (27 loc) · 696 Bytes
/
Copy pathnStep.cpp
File metadata and controls
30 lines (27 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<bits/stdc++.h>
using namespace std;
long long int steps(long long int n, int currStep, int stepVisited[]){
if(currStep>n)
return 0;
if(currStep == n)
return 1;
if(stepVisited[currStep] != -1){
return stepVisited[currStep];
}
long long int totalWays = steps(n, currStep+1, stepVisited) + steps(n, currStep+2, stepVisited);
stepVisited[currStep] = totalWays;
return totalWays;
}
int visited(long long int n){
int stepVisited[n+1];
for(int i=0; i<=n; i++){
stepVisited[i] = -1;
}
return steps(n, 0, stepVisited);
}
int main(){
long long int step;
cin >> step;
cout << visited(step);
return 0;
}