Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int A[9][362880];
- int x = 0;
- struct vect
- {
- vector<int>b;
- };
- void sl(vector <int> a, int n,bool C[11])
- {
- if (a.size() == n)
- {
- for (int i = 0;i < n;i++)
- {
- A[i][x] = a[i];
- }
- x++;
- return;
- }
- vect vect0[11];
- for (int v = 1;v < n;v++)
- {
- for (int i = 0;i < a.size();i++)
- {
- vect0[v].b.push_back(a[i]);
- }
- }
- for (int v = 1;v < n;v++)
- {
- if(!C[v])
- {
- C[v]=true;
- vect0[v].b.push_back(v);
- sl(vect0[v].b, n, C);
- C[v]=false;
- }
- }
- if (!C[n])
- {
- C[n]=true;
- a.push_back(n);
- sl(a, n, C);
- C[n]=false;
- }
- }
- int fk(int a)
- {
- int sum=1;
- for (int i = 1;i <= a;i++)
- {
- sum = sum*i;
- }
- return sum;
- }
- int main()
- {
- int a;
- cin >> a;
- bool C[11];
- for (int i = 0;i <= a;i++)
- {
- C[i] = false;
- }
- if (a == 1)
- {
- cout << "1 ";
- return 0;
- }
- vector<int>n;
- sl(n, a, C);
- for (int i = 0;i < fk(a);i++)
- {
- for (int v = 0;v < a;v++)
- {
- cout << A[v][i] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement