bzoj4788: [CERC2016]Bipartite Blanket
2019.1.9交流题,现在看还是不会,,,
如果只有一边,那么Hall定理即可。
两边?分别满足Hall定理,就是合法的!
证明(构造方案):
左集合先任意形成一个合法匹配,单点增量加入右集合和与右集合有关的边进行调整
加入bj,枚举连接bj的边,连向ai
直接大力匈牙利匹配即可。由于Hall定理成立,所过之处一定能返回true
DP之后双指针即可。
注意,左、右是空集合也合法
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-){int ret=;while(y){if(y&) ret=mul(x,ret);x=mul(x,x);y>>=;}return ret;}
template<class ...Args>il int ad(const int a,const int b,const Args &...args) {return ad(ad(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
}
// using namespace Modulo;
namespace Miracle{
const int N=;
int sz[<<N];
int lim;
struct SET{
int n;
int go[N];
int val[N];
int f[<<N];
int s[<<N];
int ok[<<N],cnt;
void in(){
for(reg i=;i<n;++i) rd(val[i]);
}
void dp(){
// cout<<"D-------P "<<endl;
f[]=;
for(reg i=;i<(<<n);++i){
int to=;
for(reg j=;j<n;++j){
if((i>>j)&) {
to|=go[j];
s[i]+=val[j];
}
}
f[i]=(sz[to]>=sz[i]);
if(f[i]){
for(reg j=;j<n;++j){
if((i>>j)&) f[i]&=f[i^(<<j)];
}
}
if(f[i]){
// cout<<" OK "<<i<<" s "<<s[i]<<endl;
ok[++cnt]=s[i];
}
}
sort(ok+,ok+cnt+);
}
}le,ri;
char s[N];
int main(){
rd(le.n);rd(ri.n);
int up=max(le.n,ri.n)+;
for(reg i=;i<le.n;++i){
scanf("%s",s);
for(reg j=;j<ri.n;++j){
if(s[j]=='') le.go[i]|=(<<j),ri.go[j]|=(<<i);
}
}
le.in();ri.in();
rd(lim); for(reg i=;i<(<<up);++i){
sz[i]=sz[i>>]+(i&);
}
le.dp();ri.dp();
// cout<<le.cnt<<" "<<ri.cnt<<endl;
ll ans=;
int ptr=ri.cnt;
for(reg i=;i<=le.cnt;++i){
while(ptr&&le.ok[i]+ri.ok[ptr]>=lim) --ptr;
// ptr=lower_bound(ri.ok+1,ri.ok+ri.cnt+1,lim-le.ok[i])-ri.ok-1;
ans+=ri.cnt-ptr;
}
cout<<ans;
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
*/
bzoj4788: [CERC2016]Bipartite Blanket的更多相关文章
- bzoj 4788: [CERC2016]Bipartite Blanket【hall定理+状压】
考虑当前合法的一个点集s,如果他合法,那么一定有一个完备匹配的点集包含这个点集,也就是两边都满足hall定理的话这两边拼起来的点集也满足要求 所以分别状压两边点集用hall定理转移判断当前点集是否合法 ...
- 【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP
题意 给一张$n\times m$二分图,带点权,问有多少完美匹配子集满足权值和大于等于$t$ 这里有一个结论:对于二分图$\mathbb{A}$和$\mathbb{B}$集合,如果子集$A \in ...
- Day5网络流
算法 无源汇上下界可行流 先强制流过l的流量 从s到每个正权点连流量为l的流量 从每个负权点向t连-l的流量 如果容量为0,则不连边 有源汇上下界最大流 去掉下界 先求出可行流 再求S到T的最大流 有 ...
- Note - 千年食谱颂
其实是兔子收集的各种下饭操作与名菜食谱.( 零·策略篇 多校 NOIP 2021.11.05: 这个真的是,我每次打毛毛虫剖分都是 rush 状态 qwq.像这种 已知代码难度大.不便于调试的 ...
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
- dataStructure@ Check whether a given graph is Bipartite or not
Check whether a given graph is Bipartite or not A Bipartite Graph is a graph whose vertices can be d ...
- hdu 5313 Bipartite Graph(dfs染色 或者 并查集)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- [LeetCode] Is Graph Bipartite? 是二分图么?
Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipart ...
- [Swift]LeetCode785. 判断二分图 | Is Graph Bipartite?
Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipart ...
随机推荐
- 计算几何——线段和直线判交点poj3304
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...
- MFC打开/保存文件对话框:CFileDialog
MFC打开/保存文件对话框:CFileDialog CFileDialog 文件选择对话框的使用:首先构造一个对象并提供相应的参数,构造函数原型如下: CFileDialog::CFileDial ...
- 双线程DP
1.传纸条 好像是一道普及组水题? //Twenty #include<cstdio> #include<iostream> #include<cstring> # ...
- [Codeplus 4月赛]最短路
题意:理论上是给定一张完全图,有边权,在给一些单向边求最短路. 思路: 我充分体会到了我图论的菜. 理论上建图肯定是不能\(n^2\)的,考虑如何优化呢? 将边权异或值二进制替换,最后一遍最短路就行, ...
- 安装Docker 服务
curl -fsSL https://get.docker.com/ | sh 执行到这一部分出错: The program 'curl' is currently not installed. Yo ...
- PAT甲级——A1125 Chain the Ropes【25】
Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...
- Hadoop完全分布式配置
***** 全部三个节点 *****1. 关闭防火墙 service iptables stop chkconfig iptables off2. 修改主机名,Hadoop主机名中不能出现_和- vi ...
- 2019 Multi-University Training Contest 6 Nonsense Time (纯暴力)
题意:给你一个n的排列,起初这些数都不能用, 然后还有一个数组 第 i 个数表示下标为 i 的数能够使用. 问每一个 i 对应的最长上升子序列. 题解: 可以通过倒推,从后往前考虑转化一下 ,然后就是 ...
- ST(RMQ)算法(在线)求LCA
在此之前,我写过另一篇博客,是倍增(在线)求LCA.有兴趣的同学可以去看一看.概念以及各种暴力就不在这里说了,那篇博客已经有介绍了. 不会ST算法的同学点这里 ST(RMQ)算法在线求LCA 这个算法 ...
- 安装Ubuntu16.04卡在logo界面
问题背景 笔者在使用U盘UEFI模式安装Ubuntu16.04时,遇到一个问题,即在BIOS里的boot设置U盘为第一启动项之后,启动,并没有顺利进入系统,而是卡在了logo界面.(PS:其实我等了它 ...