学习来自        这

主要是贡献那里不会算,很难联想到爆搜。。

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[30][30],d[30];
ll ans;
int n;
vector <int> vec;
void dfs(int pos,ll sum)
{
if(vec.size()==n){
ans=max(ans,sum);
return;
}
if(pos>2*n) return;
ll cou=d[pos];

for(int i=0;i<vec.size();i++)
cou-=2*a[pos][vec[i]];///2倍

vec.push_back(pos);
dfs(pos+1,sum+cou);
vec.pop_back();
dfs(pos+1,sum);
}
int main()
{
while(~scanf("%d",&n)){
ans=0;
for(int i=1;i<=2*n;i++)
for(int j=1;j<=2*n;j++)
scanf("%lld",&a[i][j]),d[i]+=a[i][j];
dfs(1,0);
printf("%lld\n",ans);
}
}


时间限制:C/C++ 4秒,其他语言8秒

空间限制:C/C++ 262144K,其他语言524288K

64bit IO Format: %lld

题目描述

Given 2N people, you need to assign each of them into either red team or white team such that each team consists of exactly N people and the total competitive value is maximized.


Total competitive value is the summation of competitive value of each pair of people in different team.


The equivalent equation is ∑2Ni=1∑2Nj=i+1(vij if i-th person is not in the same team as j-th person else 0)∑i=12N∑j=i+12N(vij if i-th person is not in the same team as j-th person else 0)

输入描述:

The first line of input contains an integers N.

Following 2N lines each contains 2N space-separated integers vijvij is the j-th value of the i-th line which indicates the competitive value of person i and person j.

* 1≤N≤141≤N≤14
* 0≤vij≤1090≤vij≤109
* vij=vjivij=vji

输出描述:

Output one line containing an integer representing the maximum possible total competitive value.

示例1

输入

复制

1
0 3
3 0

输出

复制

3