2019牛客多校2 F Partition problem(dfs)
题意:
n<=28个人,分成人数相同的两组,给你2*n*2*n的矩阵,如果(i,j)在不同的组里,竞争力增加v[i][j],问你怎么分配竞争力最
4s
思路:
枚举C(28,14)的状态,更新答案即可
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
//#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1 using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 1e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
//const db pi = acos(-1.0); int n;
ll v[][];
ll ans;
ll tmp;
int cnt0,cnt1;
int v0[maxn],v1[maxn];
int m;
void dfs(int x, int y){//p / num of need 1
ll now=;
if(x==m+){ans=max(ans,tmp);return;}
if(m-x>=y){
v0[++cnt0]=x;
for(int i = ; i <= cnt1; i++)now+=v[v1[i]][x];
tmp+=now;
dfs(x+,y);
tmp-=now;
cnt0--;
}
if(y>){
now=;
v1[++cnt1]=x;
for(int i = ; i <= cnt0; i++)now+=v[v0[i]][x];
tmp+=now;
dfs(x+,y-);
tmp-=now;
cnt1--;
}
return;
}
int main(){
scanf("%d", &n);
m = *n;
ans=tmp=;
cnt0=cnt1=;
for(int i = ; i <= m; i++){
for(int j = ; j <= m; j++){
scanf("%d", &v[i][j]);
}
}
dfs(,n);
printf("%lld",ans);
return ;
}
/*
2
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
*/
2019牛客多校2 F Partition problem(dfs)的更多相关文章
- 2019牛客多校第二场F-Partition problem(搜索+剪枝)
Partition problem 题目传送门 解题思路 假设当前两队的对抗值为s,如果把红队中的一个人a分配到白队,s+= a对红队中所有人的对抗值,s-= a对白队中所有人的对抗值.所以我们可以先 ...
- 2019 牛客多校五 F. maximum clique 1 (最大团)
大意: 给定$n$个互不相同的数, 若两个数异或后二进制中$1$的个数不少于$2$则连边, 求最大团. 最大团转为补图最大独立集. 可以发现补图是二分图, 所以直接$dinic$即可. 最大独立集相当 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 2019牛客多校 Round4
Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...
- 2019牛客多校 Round2
Solved:2 Rank:136 A Eddy Walker 题意:T个场景 每个场景是一个长度为n的环 从0开始 每次要么向前走要么向后走 求恰好第一次到m点且其他点都到过的概率 每次的答案是前缀 ...
- 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化
Partition problem 暴力+复杂度计算+优化 题意 2n个人分成两组.给出一个矩阵,如果ab两个在同一个阵营,那么就可以得到值\(v_{ab}\)求如何分可以取得最大值 (n<14 ...
- 2019牛客多校第一场E ABBA(DP)题解
链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 ABBA 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语 ...
随机推荐
- 对接百度地图API 实现地址转经纬度
<?php class BaiduLBS { public static $_ak = '你的KEY值'; # Util::request 是我封装的一个请求URL类,自己可以写一个 可以提交 ...
- BigInteger&BigDecimal类
BigInteger类 当需要处理超过 long 数值范围的大整数时,java.math 包中的 BigInteger 类提供任意精度的整数运算. 构造方式 //构造方法,将BigInteger的十进 ...
- Google 开源的 Python 命令行库:fire 实现 git 命令
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- 78.纯 CSS 创作 Windows 启动界面
原文地址:https://segmentfault.com/a/1190000015632759 学习后效果地址:https://scrimba.com/c/cPgWmZCg HTML code: & ...
- 如何设计一个优雅的RESTFUL的接口
show me the code and talk to me,做的出来更要说的明白 我是布尔bl,你的支持是我分享的动力! 一 .引入 设计接口是我们开发人员的日常操作.当我们把接口交给前端人员时, ...
- 双射 - hash去重
题目描述Two undirected simple graphs and where are isomorphic when there exists a bijection on V satisfy ...
- 函数组合的 N 种模式
随着以函数即服务(Function as a Service)为代表的无服务器计算(Serverless)的广泛使用,很多用户遇到了涉及多个函数的场景,需要组合多个函数来共同完成一个业务目标,这正是微 ...
- python3迭代器
一.前提 1.dir()函数 dir()函数带参数时,返回参数的属性和方法列表:不带参数时,返回当前范围内变量.方法和定义的类型列表 # dir(参数):带参数,返回参数的属性和方法 s = '' p ...
- spring boot部署中executable的系统服务
首先在pom.xml 中添加spring boot插件,并设置 <plugins> <plugin> <groupId>org.springframework.bo ...
- 我的第一个 Kaggle 比赛学习 - Titanic
背景 Titanic: Machine Learning from Disaster - Kaggle 2 年前就被推荐照着这个比赛做一下,结果我打开这个页面便蒙了,完全不知道该如何下手. 两年后,再 ...