fork(26) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,k,z,i,j ;
  6. cin>>n>>k;
  7. vector<int> A(n);
  8. for(i=0;i<n;++i){
  9. cin>>A[i];
  10. }
  11. int x = pow(2,n)-1;
  12. for(i=0;i<=x;++i) {
  13. if(__builtin_popcount(i)!=k) continue;
  14. for(j=0;j<n;++j){
  15. z = 1<<j;
  16. if(z & i){
  17. cout<<A[j]<<" ";
  18. }
  19. }
  20. cout<<endl;
  21. }
  22. }
Success #stdin #stdout 0s 2864KB
stdin
 3 2
1 2 3
stdout
1 2 
1 3 
2 3