Pagini recente » Cod sursa (job #1899101) | Cod sursa (job #371799) | Cod sursa (job #667450) | Cod sursa (job #675580) | Cod sursa (job #1566459)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("permutari.in");
ofstream out("permutari.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;
}