Cod sursa(job #2972221)

Utilizator sandry24Grosu Alexandru sandry24 Data 28 ianuarie 2023 21:28:47
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

int n, m;
vector<vi> ans;

void all_comb(int l, int r, vi &a){
    if(l == r){
        if(a.size() == m)
            ans.pb(a);
    } else {
        a.pb(l);
        all_comb(l+1, r, a);
        a.erase(a.end()-1);
        all_comb(l+1, r, a);
    }
}
 
void solve(){
    cin >> n >> m;
    vi a;
    all_comb(1, n+1, a);
    sort(ans.begin(), ans.end());
    for(auto i : ans){
        for(auto j : i)
            cout << j << ' ';
        cout << '\n';
    }
}  
 
int main(){
    freopen("combinari.in", "r", stdin);
    freopen("combinari.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}