题目链接:https://ac.nowcoder.com/acm/contest/882/F;
/*
题意:有2n个人,把2n个人分成两组,求两组的权值最大
思路:数据较小,可以暴搜,具体看代码注释
当前人加入A组是,就将当前人与B组已有的人之间的权值相加
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=30;
ll val[N][N];
ll ta,tb,n,ans,sum;
ll a[N],b[N];
ll MAX(ll x,ll y)
{
if(x<y) x=y;
return x;
}
void dfs(ll num)
{
if(ta>n||tb>n)
return;
if(ta==n&&tb==n)///符合条件就更新答案
ans=MAX(ans,sum);
else
{
if(ta<n)
{
ll tmp=0;
for(ll i=0; i<tb; i++)///将当前人与B组已有的人之间的权值相加
tmp+=val[num][b[i]];
sum+=tmp;
a[ta++]=num;
dfs(num+1);///继续搜索
a[ta--];
sum-=tmp;
}
if(tb<n)///同上
{
ll tmp=0;
for(ll i=0; i<ta; i++)
tmp+=val[num][a[i]];
sum+=tmp;
b[tb++]=num;
dfs(num+1);
b[tb--];
sum-=tmp;
}
}
}
int main()
{
scanf("%lld",&n);
for(ll i=1; i<=n*2; i++)
for(ll j=1; j<=n*2; j++)
scanf("%lld",&val[i][j]);
dfs(1);
printf("%lld\n",ans);
return 0;
}