Pagini recente » Cod sursa (job #2260021) | Cod sursa (job #2125324) | Cod sursa (job #3281251) | Cod sursa (job #1607513) | Cod sursa (job #1074840)
#include <vector>
#include <fstream>
void printSolution (const std::vector<int> &sol){
static std::ofstream fout("permutari.out");
for (int a : sol)
fout << a + 1 << ' ';
fout << std::endl;
}
void back(int depth, int n){
static std::vector<bool> used(n, false);
static std::vector<int> solution(n);
for (int i = 0; i < n; ++i)
if (!used[i]){
used[i] = true;
solution[depth] = i;
if (depth == n - 1)
printSolution(solution);
else
back(depth + 1, n);
used[i] = false;
}
}
int main(){
std::ifstream fin("permutari.in");
int n;
fin >> n;
back(0, n);
return 0;
}