Pagini recente » Cod sursa (job #727499) | Cod sursa (job #1121428) | Cod sursa (job #1058889) | Cod sursa (job #2035832) | Cod sursa (job #1094069)
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("combinari.in");
ofstream g("combinari.out");
int n,k;
int b[20];
int a[20];
void comb(const int n,const int k,int t)
{
if (t==k+1) { for (int j=1;j<=k;j++) g << a[j] << " "; g << "\n"; }
else
{
for (int j=1;j<=n;j++)
if (b[j] == 0 && a[t-1] < j ) { a[t] = j; b[j] = 1; comb(n,k,t+1); b[j] = 0; }
}
}
int main()
{
f >> n >> k;
comb(n,k,1);
return 0;
}