Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int N;
- int V[10];
- int M[10];
- ifstream i("permutari1.in");
- ofstream o("permutari1.out");
- void backtrack(int x)
- {
- if(x == N)
- {
- for(int a = 0; a < x; a++)
- {
- o << M[a] << " ";
- }
- o << '\n';
- return;
- }
- else
- {
- for(int a = N; a >= 1; a--)
- {
- if(V[a] != -1)
- {
- int bup = V[a];
- M[x] = V[a];
- V[a] = -1;
- backtrack(x + 1);
- V[a] = bup;
- }
- }
- }
- }
- int main()
- {
- i >> N;
- for(int a = 0; a <= N; a++)
- {
- V[a] = a;
- }
- backtrack(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement