Cod sursa(job #3218244)

Utilizator bogdann31Nicolaev Bogdan bogdann31 Data 26 martie 2024 16:55:41
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.31 kb
#include <bits/stdc++.h>
using namespace std;
#define ll                 long long 
#define all(v)             v.begin(), v.end()
ll ceil2(ll a, ll b) {
return (a + b - 1) / b;
}
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define mod 1000000001;

bool compare(char a, char b){
    if(a=='(') return 0;
    if(a=='*' || a=='/') return 1;
    else if(a!='*' && a!='/' && b!='*' && b!='/') return 1;
    else return 0;
}

void solve(){
    ll n, m;cin>>n>>m;
    ll v[n+1];memset(v,0, sizeof(v));
    for(int i=0; i<n; i++){
        v[i]=n-i;
    }
    for(int i=(1<<n)-1; i>=0; i--){
        if(__builtin_popcountll(i)==m){
            vector<ll> a;
            for(int j=0; (1<<j)<=i; j++){
                if((1<<j) & i){
                    a.push_back(v[j]);
                }
            }
            reverse(all(a));
            for(int j=0; j<a.size(); j++){
                cout<<a[j]<<" ";
            }
            cout<<'\n';

        }
    }
}


int main(){
    freopen("combinari.in", "rt", stdin);
	freopen("combinari.out", "wt", stdout);
   ios_base::sync_with_stdio(false); cin.tie(NULL);
//    ll t;cin>>t;while(t--){solve();cout<<endl;}
    solve();
}