Pagini recente » Istoria paginii runda/sim_2/clasament | Cod sursa (job #2262693) | Istoria paginii utilizator/watersword | Cod sursa (job #2866669) | 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;
}