Advertisement
haufont

Untitled

Jun 13th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int A[9][362880];
  5. int x = 0;
  6. struct vect
  7. {
  8. vector<int>b;
  9. };
  10. void sl(vector <int> a, int n,bool C[11])
  11. {
  12. if (a.size() == n)
  13. {
  14. for (int i = 0;i < n;i++)
  15. {
  16. A[i][x] = a[i];
  17. }
  18. x++;
  19. return;
  20. }
  21. vect vect0[11];
  22. for (int v = 1;v < n;v++)
  23. {
  24. for (int i = 0;i < a.size();i++)
  25. {
  26. vect0[v].b.push_back(a[i]);
  27. }
  28. }
  29. for (int v = 1;v < n;v++)
  30. {
  31. if(!C[v])
  32. {
  33. C[v]=true;
  34. vect0[v].b.push_back(v);
  35. sl(vect0[v].b, n, C);
  36. C[v]=false;
  37. }
  38. }
  39. if (!C[n])
  40. {
  41. C[n]=true;
  42. a.push_back(n);
  43. sl(a, n, C);
  44. C[n]=false;
  45. }
  46. }
  47. int fk(int a)
  48. {
  49. int sum=1;
  50. for (int i = 1;i <= a;i++)
  51. {
  52. sum = sum*i;
  53. }
  54. return sum;
  55. }
  56. int main()
  57. {
  58. int a;
  59. cin >> a;
  60. bool C[11];
  61. for (int i = 0;i <= a;i++)
  62. {
  63. C[i] = false;
  64. }
  65. if (a == 1)
  66. {
  67. cout << "1 ";
  68. return 0;
  69. }
  70. vector<int>n;
  71. sl(n, a, C);
  72. for (int i = 0;i < fk(a);i++)
  73. {
  74. for (int v = 0;v < a;v++)
  75. {
  76. cout << A[v][i] << " ";
  77. }
  78. cout << endl;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement