Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <numeric>
- #include <algorithm>
- #include <cmath>
- #include <cstring>
- #include <iostream>
- // constexpr void print() {
- // std::cerr << std::endl;
- // }
- // template<class... Args>
- // constexpr void print(int value, Args... args) {
- // std::cerr << value << " ";
- // print(args...);
- // }
- constexpr bool is_used(int elem) {
- return false;
- }
- template<class... Args>
- constexpr bool is_used(int elem, int value, Args... args) {
- if (value == elem) {
- return true;
- }
- return is_used(elem, args...);
- }
- template<int N, class matrix, class... Args>
- constexpr int res(const matrix& a, int i, int sign, int prod, Args... used) {
- if (i == N) {
- return sign * prod;
- }
- int sum = 0;
- for (int j = 0; j < N; ++j) {
- // if (!is_used(j, used...)) {
- if (j == i) {
- int new_sign = sign;
- int new_prod = prod * a[i][j];
- sum += res<N>(a, i + 1, new_sign, new_prod, j, used...);
- }
- }
- return sum;
- }
- template<int N>
- constexpr int determinant(const std::array<std::array<int, N>, N>& a) {
- // int det = 0;
- // std::array<int, 3> a = {0, 1, 2};
- // int perm[N];
- // std::iota(perm, perm + N, 0);
- // int sign = 1;
- // do {
- // int det_perm = sign;
- // for (int i = 0; i < N; ++i) {
- // det_perm *= a[i][perm[i]];
- // }
- // det += det_perm;
- // sign *= -1;
- // } while (std::next_permutation(perm, perm + N));
- // return det;
- return res<N>(a, 0, 1, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement