洛谷 1894 [USACO4.2]完美的牛栏The Perfect Stall
来源:互联网 发布:淘宝什么推广效果好 编辑:程序博客网 时间:2024/05/22 15:52
题目:
https://www.luogu.org/problem/show?pid=1894
裸的二分图最大匹配;
直接跑匈牙利;
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=2001;int n,m,tot,cnt;int fst[MAXN],nxt[MAXN],sc[MAXN];bool vis[MAXN];struct hh{ int from,to;}ma[MAXN<<1];void build(int f,int t){ tot++; ma[tot]=(hh){f,t}; nxt[tot]=fst[f]; fst[f]=tot; return;}bool dfs(int x){ for(int i=fst[x];i;i=nxt[i]) { int v=ma[i].to; if(!vis[v]) { vis[v]=1; if(!sc[v] || dfs(sc[v])) { sc[v]=x; return true; } } } return false;}void solve(){ int num,x; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&x); build(i,x); } } for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) cnt++; } cout<<cnt; return;}int main(){ solve(); return 0;}
阅读全文
1 0
- 洛谷 1894 [USACO4.2]完美的牛栏The Perfect Stall
- Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall
- 洛谷P1894 [USACO4.2]完美的牛栏The Perfect Stall
- usaco-4.2.2The Perfect Stall完美的牛栏
- POJ1274 The Perfect Stall_洛谷P1894 [USACO4.2]完美的牛栏
- USACO 4.2 The Perfect Stall 完美的牛栏(最大匹配)
- USACO 4.2 The Perfect Stall 完美的牛栏(最大匹配)
- USACO 4.2 The Perfect Stall 完美的牛栏(最大匹配)
- (洛谷P1894)USACO 4.2 The Perfect Stall 完美的牛栏
- USACO 4.2.2The Perfect Stall 完美的牛栏(二分图最大匹配)
- 【CJOJ1167】【洛谷1894】[USACO4.2]完美的牛栏
- The Perfect Stall 完美的牛栏 二分图最大匹配,匈牙利算法
- [USACO4.2.2]The Perfect Stall
- usaco training 4.2.2 The Perfect Stall 最佳牛栏 题解
- USACO4.2.2 The Perfect Stall (stall4)
- USACO4.2.2 The Perfect Stall (stall4)
- 【USACO4.2.2】完美的牛栏 二分图的匹配
- USACO 4.2.2 The Perfect Stall
- 为什么说jsp是servlet?JSP是如何转换成servlet的?
- org.hibernate.MappingException: Unknown entity:的解决办法
- Tableviewcell的registerNib与registerClass的差异
- iOS 11适配之跳转App Store评论
- Linux下SGX的使用(3)-编译多个文件
- 洛谷 1894 [USACO4.2]完美的牛栏The Perfect Stall
- java中关于final方法与static方法不具备多态性的理解
- mac 使用java命令运行class文件提示“错误:找不到或无法加载主类“
- HTTP的长连接和短连接
- Redis,Geo,(地理位置信息操作)
- 深入浅出~spring IOC和DI
- jsTree异步动态加载子节点
- 2017.10.13 shell rmp命令详解
- Windows-Caffe Cifar10模型的生成