Print all ways to reach the Nth stair with the jump of 1 or 2 units at a time | C ++ program for the above approach ; Function to find all the ways to reach Nth stair using one or two jumps ; Base Cases ; Recur for jump1 and jump2 ; Stores the total possible jumps ; Add "1" with every element present in jump1 ; Add "2" with every element present in jump2 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < string > TotalPossibleJumps ( int N ) { if ( ( N - 1 ) == 0 ) { vector < string > newvec ; newvec . push_back ( " " ) ; return newvec ; } else { if ( N < 0 ) { vector < string > newvec ; return newvec ; } } vector < string > jump1 = TotalPossibleJumps ( N - 1 ) ; vector < string > jump2 = TotalPossibleJumps ( N - 2 ) ; vector < string > totaljumps ; for ( string s : jump1 ) { totaljumps . push_back ( "1" + s ) ; } for ( string s : jump2 ) { totaljumps . push_back ( "2" + s ) ; } return totaljumps ; } int main ( ) { int N = 3 ; vector < string > Ans = TotalPossibleJumps ( N ) ; for ( auto & it : Ans ) cout << it << ' ' ; return 0 ; }