题目地址:点这里
直接暴力枚举排列~
额.... 西安回来以后好久没碰代码了.. 写一点简单题解
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int g[5][5];
int a[5];
typedef long long LL;
LL calc(int *p)
{
LL ans=0;
ans+=g[p[0]][p[1]]+g[p[1]][p[0]];
ans+=2*(g[p[2]][p[3]]+g[p[3]][p[2]]);
ans+=g[p[1]][p[2]]+g[p[2]][p[1]];
ans+=2*(g[p[3]][p[4]]+g[p[4]][p[3]]);
return ans;
}
int main()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
cin>>g[i][j];
}
for(int i=0;i<5;i++)
a[i]=i;
LL max=-1;
do{
LL cur=calc(a);
if(cur>max)
{
max=cur;
}
}
while (next_permutation(a, a+5));
cout<<max<<endl;
}