#include <iostream>
using namespace std;
const int MAXN = 100;
int det(int a[MAXN][MAXN], int n) {
int res = 0;
if (n == 1) {
return a[0][0];
} else {
for (int j = 0; j < n; j++) {
int t[MAXN][MAXN];
for (int i = 1; i < n; i++) {
int k = 0;
for (int p = 0; p < n; p++) {
if (p == j) {
continue;
}
t[i - 1][k++] = a[i][p];
}
}
res += ((j % 2 == 1) ? -1 : 1) * a[0][j] * det(t, n - 1);
}
}
return res;
}
int main() {
int n;
cin >> n; // 输入矩阵的大小
int a[MAXN][MAXN];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
cout << det(a, n) << endl; // 求解矩阵行列式并输出
return 0;
}
标签:return,int,模版,矩阵,++,MAXN,行列式,res
From: https://www.cnblogs.com/swjswjswj/p/18323016