poj2239(二分图)
来源:互联网 发布:万能五笔有mac版吗 编辑:程序博客网 时间:2024/04/30 07:27
题意:不多写了,又是裸的二分图匹配;
解法:写这道题时,第一次用邻接表建图写了匈牙利。而且还从neko那里学了一招,就是匈牙利的used函数在for循环里可以不用memset,用一个ncase代替就可以,降低了很多时间复杂度,瞬间觉得又学了的一招。
代码:
/***************************************************** author:xiefubao*******************************************************/#pragma comment(linker, "/STACK:102400000,102400000")#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <vector>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <string.h>using namespace std;#define eps 1e-8typedef long long LL;int used[110];int match[310];bool num[310][100];struct edge{ int v; int next;} edges[310000];int head[31000];int count1=0;int ncase=0;void addedge(int u,int v){ edges[count1].v=v; edges[count1].next=head[u]; head[u]=count1++;}int n;bool dfs(int k){ for(int i=head[k];i!=-1;i=edges[i].next) { int t=edges[i].v; if(used[t]!=ncase) { used[t]=ncase; if(match[t]==-1||dfs(match[t])) { match[t]=k; return true; } } } return false;}int main(){ while(cin>>n) { count1=0; memset(head,-1,sizeof head); memset(match,-1,sizeof match); for(int i=0;i<n;i++) { int t;scanf("%d",&t); for(int j=0;j<t;j++){ int a,b;scanf("%d%d",&a,&b); addedge(i+1,(a-1)*12+b); } } int ans=0; for(int i=1;i<=n;i++) { ncase++; if(dfs(i)) ans++; } cout<<ans<<'\n'; } return 0;}
0 0
- poj2239(二分图)
- POJ2239 二分图最大匹配
- POJ2239 Selecting Courses(二分图)
- poj2239——Selecting Courses(二分图匹配)
- poj2239 Selecting Courses --- 二分图最大匹配
- POJ2239 Selecting Courses【二分图最大匹配】
- POJ2239简单二分匹配
- POJ2239二分匹配
- poj2239 poj1274【二分匹配】
- poj2239 Selecting Courses(最大二分图匹配 (匈牙利算法) 实现 )
- POJ2239 Selecting Courses(二分图匹配,匈牙利算法)
- poj2239
- poj2239
- POJ2239
- POJ2239
- poj2239 - Selecting Courses
- poj2239 Selecting Courses
- POJ2239:Selecting Courses
- AE开发 遇到未能加载文件或程序集的问题 FileNotFoundException
- Remove Old Kernels In Ubuntu With One Command
- appStore上传苹果应用程序软件发布流程
- javascript学习笔记五:javascript中的回调函数
- libQtCore.so: undefined reference to `clock_gettime'
- poj2239(二分图)
- Android Application的作用
- CvMat Mat IplImage 之间相互转化
- smart210 的Android源码编译
- web知识笔记:select 传值与赋值
- 将Python程序打包成可执行文件
- Java 多态与父类的设计相关
- HDU-2157 How many ways?? 矩阵快速幂
- Linux学习记录--文件备份|还原