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 ...
随机推荐
- html5 js 监听网络在线与离线
<!doctype html> <html> <head> <meta http-equiv="content-type" content ...
- Vue学习笔记——Vue-router
转载:https://blog.csdn.net/guanxiaoyu002/article/details/81116616 第1节:Vue-router入门 .解读router/index.js文 ...
- Vuex听说很难?
Vuex 是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件状态,并以相应的规则保证状态以一种可预测的方式发生变化. 什么鬼东西 看完这段 ...
- 可拖拽排序的vue组件
最近在优化一个vue的博客系统,想实现文章列表处的文章拖拽功能.就试了一下awe-dnd vue插件,觉得还挺好用的. 安装 npm install awe-dnd --save 使用 在main.j ...
- hdu-4893
http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意: 给定一个数组a,一开始数组里面的元素都是0,现在有三个操作: 操作1:给第k个数字加上d. 操作2 ...
- Searching the String ZOJ - 3228 AC自动机查询升级版
题意:先给你一个不超过1000000长度的大串s:接下来输入一个n代表接下来输入的小串个数,小串长度不超过6. 小串分两种类型0和1类型. 0类型表示小串在大串中的最大匹配个数就是常规的AC自动机的做 ...
- C++开发系列-纯虚函数和抽象类
概念 纯虚函数和抽象类 纯虚函数是一个在基类中说明的虚函数,在基类中没有定义,要求任何派生类都实现该函数. 纯虚函数为各派生类提供了一个公共界面(接口的封装和设计.软件的模块功能的划分) 纯虚函数说明 ...
- 小程序怎样控制rich-text中的<img>标签自适应
小程序通过rich-text实现字符串转化为html,即 <rich-text node="{{html}}"></rich-text>.如果html字符串 ...
- 廖雪峰Java13网络编程-2Email编程-1发送email
1.邮件发送 1.1传统邮件发送: 传统的邮件是通过邮局投递,从一个邮局到另一个邮局,最终到达用户的邮箱. 1.2电子邮件发送: 与传统邮件类似,它是从用户电脑的邮件软件(如outlook)发送到邮件 ...
- 廖雪峰Java11多线程编程-3高级concurrent包-9Fork_Join
线程池可以高效执行大量小任务: Fork/Join线程池可以执行一种特殊的任务: 把一个大任务拆成多个小任务并行执行 Fork/Join是在JDK 1.7引入的 示例:计算一个大数组的和 Fork/J ...