If sequence? Recursivity?

4

I HIGHLIGHT THAT I'M JUST IN PR2 AND THERE ARE MANY THINGS THAT I STILL DO NOT, APOLOGIZE MY IGNORANCE

(It has to be resolved with recursion)

Good this is my code in which I try to solve the problem of the image above, which I do not understand because in my code it only shows me two possible ways when, example using n = 3, it would have 0123,013,023. while it only shows me 0123,023. A help please, thank you

   #include <iostream>
using namespace std;
void caminos (int,int);

int main(){
    int i=0,n=0;
    cout<<"Inserte tamaño de la Rayuela: ";
    cin>>n;
    caminos(i,n);
return 0;
}
void caminos (int i,int n){
    if(i<=n){
        cout<<i;
        caminos(i+1,n);
        if(i+2<n){
             cout<<i;
             caminos(i+2,n);
            }
    }
    else{
        cout<<endl;
    }
}
    
asked by Daniel Peña 28.05.2016 в 02:17
source

1 answer

2

I do not know what the hopscotch is, but based on the result that you put that you should get you may have or forget to use = , <= instead of < in the second if of paths :

if(i+2<=n){
#include <iostream>
using namespace std;
void caminos (int,int);

int main(){
    int i=0,n=0;
    cout<<"Inserte tamaño de la Rayuela: ";
    cin>>n;
    caminos(i,n);
return 0;
}
void caminos (int i,int n){
    if(i<=n){
        cout<<i;
        caminos(i+1,n);
        if(i+2<=n){
             cout<<i;
             caminos(i+2,n);
            }
    }
    else{
        cout<<endl;
    }
}

test

test

    
answered by 28.05.2016 / 03:56
source