19牛客暑期多校 round2 F dfs
题目传送门//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);
}
19牛客暑期多校 round2 F dfs的更多相关文章
- 19牛客暑期多校 round2 H 01矩阵内第二大矩形
题目传送门//res tp nowcoder 目的 给定n*m 01矩阵,求矩阵内第二大矩形 分析 O(nm)预处理01矩阵为n个直方图,问题转换为求n个直方图中的第二大矩形.单调栈计算,同时维护前二 ...
- 19牛客暑期多校 round1 A 有关笛卡尔树的结论
题目传送门//res tp nowcoder 分析 定理:B1~B2当且仅当B1与B2有同构的笛卡尔树. (B₁~B₂ iff B₁ and B₂ have isomorphic Cartesian ...
- 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)
layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...
- 2021牛客暑期多校训练营3 J 思维
传送门 J-Counting Triangles_2021牛客暑期多校训练营3 (nowcoder.com) 题目 Goodeat finds an undirected complete graph ...
- 2019牛客暑期多校训练营(第二场)F.Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...
- 2019牛客暑期多校训练营(第五场)F maximum clique 1 二分图求最大独立集
https://ac.nowcoder.com/acm/contest/885/F #include <bits/stdc++.h> //CLOCKS_PER_SEC #define se ...
- B-xor_2019牛客暑期多校训练营(第四场)
题意 给出n个数组(每组数个数不定),m个询问 l, r, x 序号在区间\([l,r]\)的每个数组是否都可以取出任意个数异或出x 题解 判断一个数组能否异或出x,是简单的线性基问题 判断多个线性基 ...
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- 2019牛客暑期多校训练营(第八场)E.Explorer
链接:https://ac.nowcoder.com/acm/contest/888/E来源:牛客网 Gromah and LZR have entered the fifth level. Unli ...
随机推荐
- shell脚本中${...}函数的用法总结
${...}在字符串中有非常多的用法: 1.${var} 限定变量. 如果一个变量名A是另一个变量名AB的前部分,那么,如果要在AB相连时,要得到A的值,就必须使用${var}限定. 如果变量名不会产 ...
- C++虚函数和成员函数内存 this指针问题
father* p=new son; p->disp(...); 发现有好多人this指针的本质有错误的认识,估计不少人一说起this指针,脑袋立即反应出:那个类里使用的this指针,那么这个指 ...
- shell中命令代换$()与`` 、 变量代换${} 、 整数运算$(( )) 的区别
命令代换$()与`` . 变量代换${} . 整数运算$(( )) 1.$( ) 与 ` ` (反引号) 在 bash shell 中,$( ) 与 ` ` (反引号) 都是用来做命令替换用(comm ...
- python 绘制五角星
code import turtle n = eval(input("请输入五角星的长度")) turtle.begin_fill() #开始填充颜色 i = : turtle.f ...
- 记一次phoenix在不加索引的情况调优,由6s以上时间变成不到1s
背景: 网约车预约单查询: 这里面恶心的地方是: 1个时间窗口要查询6种时间:推送订单时间(来自mongodb).有效抢单时间(来自mongodb).抢单成功时间(实时kafka).取消订单时间(实时 ...
- Guava中Lists.partition(List, size) 方法懒划分/懒分区
目录 Guava中Lists.partition(List, size) 方法懒划分/懒分区 背景 分析 总结 Guava中Lists.partition(List, size) 方法懒划分/懒分区 ...
- polya置换
UVA10294 POLYA定理的基本应用 题意:有n个珠子围成的环,有t种颜色可以染这些珠子:如果这个环可以旋转有几种办法:如果这个环可以旋转,且可以翻转,有几种办法: 参考博客 刘汝佳的分析: 等 ...
- start-20180323
几年前申请了博客,http://www.cnblogs.com/cdfive/,一篇文章没写-_-|| 账号都忘了orz.. 又到了离职的时候,开始重新找工作: 昨天一家平台好的单位面试没过,可能是跳 ...
- [MyBatis]最简MyBatis工程
下载地址:https://files.cnblogs.com/files/xiandedanteng/fillMillionDatum01_191005.rar --END-- 2019年10月5日1 ...
- pytorch-卷积基本网络结构-提取网络参数-初始化网络参数
基本的卷积神经网络 from torch import nn class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self ...