Pagini recente » Cod sursa (job #2674250) | Cod sursa (job #1931647) | Cod sursa (job #2587647) | Cod sursa (job #3128457) | Cod sursa (job #2436462)
#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;
}