题目传送门//res tp nowcoder

dfs

先将所有人都归于一队,之后从一队中取出人放置到另一个队。

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
int n;
const int L = 30;
ll a[L][L];
ll sum[L];
ll ans;
vector<int>v;
void dfs(int x,ll re){
int len = v.size();
if(len == n){ans = ans>re?ans:re;return;}//队满
if(x>2*n) return;//越界
if(x >n + 1 + len) return;//即使将剩下的人全部划分到另一队,其人数也不足n
ll t = sum[x];
for(auto s:v) t -= a[x][s]*2;
v.push_back(x);
dfs(x+1,re + t);
v.pop_back();
dfs(x+1,re);
}
int main(){
scanf(" %d",&n);
for(int i = 1;i<=n*2;++i)
for(int j = 1;j<=n*2;++j){
scanf(" %lld",&a[i][j]);
sum[i] += a[i][j];
}
dfs(1,0);
printf("%lld\n",ans);
}

最新文章

  1. gerrit 为每个工程设置提交的reviewer
  2. 程序员玩转A股
  3. 在自定义TableViewCell类里面添加按钮事件触发不了的一些实践
  4. Linux 夸平台 移植 Win32
  5. 如何将 Cortana 与 Windows Phone 8.1 应用集成 ( Voice command - Natural language recognition )
  6. Leetcode#73 Set Matrix Zeroes
  7. Android应用中-更新提示显示红点的方案
  8. poj 2513 Colored Sticks(欧拉路径+并检查集合+特里)
  9. 【css3网页布局】flex盒子模型
  10. 如何在前端模版引擎开发中避免使用eval函数
  11. 部署服务能在Dynamics CRM Online上使用吗?
  12. ajax data属性传值的方式总结
  13. 04_ switch 练习 _ 你及格了吗
  14. &lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;会报错
  15. 8 种常被忽视的 SQL 错误用法
  16. spring cloud:config-server中@RefreshScope的&quot;陷阱&quot;
  17. 福尔摩斯基本演绎法第一季/全集Elementary迅雷下载
  18. OpenCV 学习笔记03 findContours函数
  19. Oracle EBS GL 创建会计科目
  20. vsftp -samba-autofs

热门文章

  1. 日期与时间(C/C++)
  2. MySQL初识数据库
  3. axios 是如何封装 HTTP 请求的
  4. Ubuntu切换登录用户和root用户
  5. Java 标准 IO 流编程一览笔录( 上 )
  6. SchedulerFactoryBean的问题
  7. Leetcode题目136.只出现一次的数字(简单)
  8. centos7搭建hadoop-2.7.3,zookeeper-3.4.6,hbase-1.2.5(root用户)
  9. mp3收藏
  10. OpenCV中出现“Microsoft C++ 异常: cv::Exception,位于内存位置 0x0000005C8ECFFA80 处。”的异常