Advertisement
anechka_ne_plach

Untitled

Nov 6th, 2021
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <array>
  2. #include <numeric>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <cstring>
  6.  
  7. template<int N>
  8. constexpr int determinant(const std::array<std::array<int, N>, N>& a) {
  9.     int det = 0;
  10.     std::array<int, N> perm;
  11.     std::iota(perm.begin(), perm.end(), 0);
  12.     int cnt = 0;
  13.     do {
  14.         for (int i = 0; i < N; ++i) {
  15.             std::cout << i << " " << perm[i] << "\n";
  16.             det += pow(-1, cnt) * a[i][perm[i]];
  17.         }
  18.         ++cnt;
  19.         std::cout << "\n";
  20.     } while (std::next_permutation(perm.begin(), perm.end()));
  21.     return det;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement