Pagini recente » Cod sursa (job #1960858) | Cod sursa (job #997181) | Cod sursa (job #139203) | Cod sursa (job #1527597) | Cod sursa (job #2133482)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
vector<int> v;
int n, i, k;
bool valid(int k)
{
for(i=1;i<k;i++)
if(v[i]==v[k])return 0;
return 1;
}
void bkt()
{
k=1;
v[k]=0;
while(k>0)
{
while(v[k]<n&&k<=n)
{
v[k]++;
if(valid(k))
{
if(k==n)
{
for(i=1;i<=n;i++)
g<<v[i]<<' ';
g<<'\n';
}
else
{
k++;
v[k]=0;
}
}
}
k--;
}
}
int main()
{
f>>n;
v.resize(n+1);
bkt();
f.close();
g.close();
return 0;
}