Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
814 B
2
Indexable
Never

#include <bits/stdc++.h>

using namespace std;

ifstream fin("2genc.in");
ofstream fout("2genc.out");

int n, m, v[10], k;

void afisare(int k, int v[]){
    for(int i=1; i<=k; i++){
        fout<<v[i]<<" ";
    }
    fout<<endl;
}

bool isok(int k, int v[]){
    if(k==1){
        return true;
    }
    else{
        if(v[k]>=v[k-1]) return true;
        else if(v[k-1]-v[k]==1) return true;
        else return false;
    }
}

void backtracking(int n, int v[], int k, int m){
    for(int i=1; i<=n; i++){
        v[k]=i;
        if(isok(k, v)){
            if(k==m){
                afisare(k, v);
            }
            else{
                backtracking(n, v, k+1, m);
            }
        }
    }
}

void solve(){
    fin>>n>>m;
    backtracking(n, v, 1, m);
}

int main(){
    solve();
    return 0;
}