Pagini recente » Cod sursa (job #1000869) | Cod sursa (job #997867) | Cod sursa (job #981913) | Cod sursa (job #1393099) | Cod sursa (job #1566460)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("combinari.in");
ofstream out("combinari.out");
int st[1001], k, n,c;
void tipar(int k)
{
for(int i=1;i<=k;i++)
out<<st[i]<<' ';
out<<"\n";
}
bool valid(int k)
{
for(int i=1;i<k;i++)
if(st[i]==st[k] || st[i]>=st[k])
return 0;
return 1;
}
void back(int k)
{
for(int x=1; x<=n;x++)
{
st[k]=x;
if(valid(k))
{
if(k==c)
tipar(k);
else
back(k+1);
}
}
}
int main()
{
in>>n>>c;
back(1);
return 0;
}