cf 431B

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
	int iniNum[5]={0,1,2,3,4};
	int allTation[121][5];
	for(int i=0;i<120;i++){
		for(int j=0;j<5;j++)
			allTation[i][j]=iniNum[j];
		next_permutation(iniNum,iniNum+5);
	}
	int matrixHappy[5][5];
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			cin>>matrixHappy[i][j];
	int maxSum = 0;
	for(int i=0;i<120;i++){

		int hereSum = 
			matrixHappy[allTation[i][0]][allTation[i][1]]+
			matrixHappy[allTation[i][1]][allTation[i][0]]+
			matrixHappy[allTation[i][1]][allTation[i][2]]+	
			matrixHappy[allTation[i][2]][allTation[i][1]]+
			2*matrixHappy[allTation[i][3]][allTation[i][4]]+
			2*matrixHappy[allTation[i][4]][allTation[i][3]]+
			2*matrixHappy[allTation[i][2]][allTation[i][3]]+
			2*matrixHappy[allTation[i][3]][allTation[i][2]];
		maxSum = maxSum>hereSum?maxSum:hereSum;


	}
	cout<<maxSum<<endl;
	return 0;
}

你可能感兴趣的:(cf 431B)