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 ...
随机推荐
- LUOGU P4042 [AHOI2014/JSOI2014]骑士游戏 (spfa+dp)
传送门 解题思路 首先设\(f[x]\)表示消灭\(x\)的最小花费,那么转移方程就是 \(f[x]=min(f[x],\sum f[son[x]] +s[x])\),如果这个转移是一个有向无环图,那 ...
- hibernate_06_hibernate的延迟加载和抓取策略
1.延迟加载 1>类级别的延迟加载 指的是通过oad方法查询某个对象的时候,是否采用延迟, session. load(Customer class1L) 类级别延迟加载通过<class& ...
- HttpURLConnection与HttpClient浅析AAAA
. GET请求与POST请求 HTTP协议是现在Internet上使用得最多.最重要的协议了,越来越多的Java应用程序需要直接通过HTTP协议来访问网络资源. 在介绍HttpURLConnectio ...
- python爬取(自动化)豆瓣电影影评,并存储。
from selenium import webdriverfrom selenium.webdriver import ActionChainsimport time driver = webdri ...
- Spring 声明式事务管理(11)
案例分析 本案例是图书管理系统精简部分,在数据库中有3张表.分别保存图书库存.图书信息和用户信息.下面是建表SQL语句 1 DROP TABLE IF EXISTS store; 2 DROP TAB ...
- 编写Map处理逻辑
- Luogu P2827 蚯蚓(模拟)
P2827 蚯蚓 题意 题目描述 本题中,我们将用符号\(\lfloor c\rfloor\)表示对\(c\)向下取整,例如:\(\lfloor 3.0\rfloor =\lfloor 3.1\rfl ...
- QSerialPort类
一.简介 QSerialPort类是Qt5封装的串口类,可以与串口进行通信.QSerialPortInfo是一个辅助类,提供串口的一些信息,如可用的串口名称,描述,制造商,序列号,串口16位产 ...
- 【SDOI2015】约数个数和
题面 求\(\sum_{i=1}^n\sum_{j=1}^md(ij)\) \(\leq 50000\)组数据,\(1\leq n,m\leq 50000\). 题目分析 首先,你需要知道一个结论: ...
- leetcode-154-寻找旋转排序数组中的最小值
题目描述: 方法一: class Solution: def findMin(self, nums: List[int]) -> int: left, right = 0, len(nums) ...