Pagini recente » Cod sursa (job #13326) | Cod sursa (job #301368) | Cod sursa (job #2653271) | Cod sursa (job #988226) | Cod sursa (job #3297409)
#include <stdio.h>
#include <vector>
#include <algorithm>
int main() {
FILE *fin = fopen( "combinari.in", "r" );
FILE *fout = fopen( "combinari.out", "w" );
int n, k;
fscanf( fin, "%d%d", &n, &k );
std::vector<std::vector<int>> mata;
for( int mask = (1 << n); mask--; ){
if( __builtin_popcount( mask ) != k ) continue;
mata.emplace_back();
for( int i = 0; i < n; i++ )
if( mask & (1 << i) )
mata.back().push_back( 1 + i );
}
std::sort( mata.begin(), mata.end() );
for( auto &row : mata ){
for( int x : row ) fprintf( fout, "%d ", x ); fputc( '\n', fout );
}
fclose( fin );
fclose( fout );
return 0;
}