-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstairPath.cpp
More file actions
44 lines (39 loc) · 942 Bytes
/
Copy pathstairPath.cpp
File metadata and controls
44 lines (39 loc) · 942 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Question : https://youtu.be/W6cT68K7Hls?list=PL-Jc9J83PIiFj7YSPl2ulcpwy-mwj1SSk
//Explanation : https://www.pepcoding.com/resources/online-java-foundation/recursion-with-arraylists/get_stair_paths/topic
//Solution : https://youtu.be/hMJAlbJIS7E?list=PL-Jc9J83PIiFj7YSPl2ulcpwy-mwj1SSk
#include<vector>
#include<string>
#include<iostream>
using namespace std;
void getStairPath(int n,vector<string> &v,string temp)
{
if(n<0)
{
return;
}
else if(n==0)
{
v.push_back(temp);
}
else
{
//taking one step
getStairPath(n-1,v,temp+"->1");
//taking two steps
getStairPath(n-2,v,temp+"->2");
//taking 3 steps
getStairPath(n-3,v,temp+"->3");
}
}
int main()
{
int n;
cin>>n;
vector<string> v;
getStairPath(n,v,"");
cout<<"Total number of ways : "<<v.size()<<"\n\n";
for(auto &ways:v)
{
cout<<ways<<"\n";
}
}