Cod sursa(job #2436462)
| Utilizator | Data | 5 iulie 2019 20:49:35 | |
|---|---|---|---|
| Problema | Combinari | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int n,K,solutions[19];
bool isValid(int k)
{
for(int i=1;i<k;i++)
if(solutions[k]<=solutions[i])
return false;
return true;
}
void read()
{
fin>>n>>K;
}
void write()
{
for(int i=1;i<=K;i++) fout<<solutions[i]<<' ';
fout<<'\n';
}
void generate(int k)
{
for(int i=1;i<=n;i++)
{
solutions[k]=i;
if(isValid(k))
{
if(k==K) write();
else generate(k+1);
}
}
}
int main()
{
read();
generate(1);
return 0;
}