题目出错了
#include <iostream>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <algorithm>
#include<cstdlib>
#include<vector>
//用过的Q
int* Qused = new int[10005]{ 0 };
//最大值
int maxValue = 0;
//当前值
int curSum = 0;
void recursion(int i, int n, int** P, int** Q) {
//如果越界了,代表填完了,看哪个大
if (i == n) {
maxValue = max(maxValue, curSum);
return;
}
//正常情况
//对i,从Q中选
for (int k = 0; k < n; k++) {
//如果被选过了,下一个
if (Qused[k] != 0) {
continue;
}
//加到当前和
curSum += P[i][k] * Q[k][i];
//用过了
Qused[k] = 1;
//选下一个i
recursion(i + 1, n, P, Q);
//回溯
curSum -= P[i][k] * Q[k][i];
Qused[k] = 0;
}
}
int main()
{
int n;
cin >> n;
int** P = new int* [n];
int** Q = new int* [n];
for (int i = 0; i < n; i++) {
P[i] = new int[n];
for (int j = 0; j < n; j++) {
cin >> P[i][j];
}
}
for (int i = 0; i < n; i++) {
Q[i] = new int[n];
for (int j = 0; j < n; j++) {
cin >> Q[i][j];
}
}
//最大值
maxValue = 0;
recursion(0, n, P, Q);
cout << maxValue << endl;
return 0;
}