题意:把2n个人分成相同两组,分完之后的价值是val(i, j),其中i属于组1, j属于组2,已知val表,n <= 14

思路:直接dfs暴力分组,新加的价值为当前新加的人与不同组所有人的价值。复杂度$O(C_{2n}^n * n)$。

大概6e8这样子,

代码:

#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 30 + 5;
const int M = 50 + 5;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int n;
int t1[20], t2[20];
ll v[maxn][maxn];
ll ans;
void dfs(int pos, int cnt1, int cnt2, ll ret){
if(cnt1 == cnt2 && cnt1 == n){
ans = max(ans, ret);
return;
}
ll tmp = 0;
if(cnt1 < n){
for(int i = 0; i < cnt2; i++){
tmp += v[pos][t2[i]];
}
t1[cnt1] = pos;
dfs(pos + 1, cnt1 + 1, cnt2, ret + tmp);
}
tmp = 0;
if(cnt2 < n){
for(int i = 0; i < cnt1; i++){
tmp += v[pos][t1[i]];
}
t2[cnt2] = pos;
dfs(pos + 1, cnt1, cnt2 + 1, ret + tmp);
}
}
int main(){
scanf("%d", &n);
ans = 0;
for(int i = 0; i < 2 * n; i++){
for(int j = 0; j < 2 * n; j++){
scanf("%lld", &v[i][j]);
}
}
dfs(0, 0, 0, 0);
printf("%lld\n", ans);
return 0;
}

最新文章

  1. 【C#公共帮助类】 Log4net 帮助类
  2. 【原】一张图片优化5K的带宽成本
  3. CentOS6.0(64位)安装Apache+PHP+Mysql教程,安装Magento(解决DOM,Mcrypt,GD问题)完整教程
  4. iOS开发UI篇—ios应用数据存储方式(偏好设置)
  5. javax.el.PropertyNotFoundException: Property &#39;aDesc&#39; not found on type
  6. 读取Excel异常定义了过多字段的解决方法
  7. MySQL分表
  8. 数据可视化的开源方案: Superset vs Redash vs Metabase (二)
  9. C# ConcurrentBag实现
  10. RCNN
  11. Redis五种数据结构简介-2
  12. Java内存模型-锁的内存语义
  13. Python学习笔记二:函数式编程
  14. MyEclipse 2014 破解图文详细教程
  15. 数字与字符串之间的转换以及%f与%lf的输入输出用法区别
  16. centos7.2+php7.2+nginx1.12.0+mysql5.7配置
  17. JavaScript编写简单的增加与减少元素
  18. js post
  19. node.js 之 http 架设
  20. Linux 添加虚拟网卡

热门文章

  1. Maven + springboot + mybatis 构建多模块工程
  2. pyinstaller打包shotgun有关的程序
  3. Simple decorator that intercepts connection errors and ignores these if settings specify this.
  4. (Oracle)已有数据表建立表分区—在线重定义
  5. 无刷电调基础知识以及BLHeli固件烧录和参数调整
  6. Web下无插件播放rtsp视频流的方案及各家优秀内容资源整理
  7. 数据库备份和恢复---MariaDB
  8. jackson学习之九:springboot整合(配置文件)
  9. leetcode常见问题
  10. Codeforces Round #651 (Div. 2) B. GCD Compression(数论)