HDU 2063 过山车( 最大匹配 )
2015-08-18 20:51
232 查看
题意:中文
思路:最大匹配
思路:最大匹配
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<set> #include<map> #include<string> #include<cstring> #include<stack> #include<queue> #include<vector> #include<limits> #include<ctime> #include<cassert> #include<cstdlib> #define lson (rt<<1),L,M #define rson (rt<<1|1),M+1,R #define M ((L+R)>>1) #define cl(a,b) memset(a,b,sizeof(a)); #define LL long long #define P pair<int,int> #define X first #define Y second #define pb push_back #define fread(a) freopen(a,"r",stdin); #define fwrite(a) freopen(a,"w",stdout); using namespace std; const int maxn=505; const int inf=999999; vector<int> G[maxn]; int matching[maxn]; bool vis[maxn]; int num; bool dfs(int u){ int N=G[u].size(); for(int i=0;i<N;i++){ int v=G[u][i]; if(vis[v])continue; vis[v]=true; if(matching[v]==-1||dfs(matching[v])){ matching[v]=u; return true; } } return false; } int hungar(){ int ans=0; cl(matching,-1); for(int i=0;i<num;i++){ cl(vis,false); if(dfs(i))ans++; } return ans; } int main(){ int n,m,k; while(~scanf("%d",&k)&&k){ scanf("%d%d",&m,&n); for(int i=0;i<maxn;i++)G[i].clear(); while(k--){ int x,y; scanf("%d%d",&x,&y); x--;y--; G[x].pb(y); } num=max(n,m); printf("%d\n",hungar()); } return 0; }
相关文章推荐
- Result Maps collection already contains value for **
- ACM-数学知识的算法应用
- HDU3308 LCIS 最长连续上升序列。
- ros消息时间同步与回调
- 笔记本wifi共享给手机 连接连笔记本wifi
- java 引用类型 和 基本类型的理解
- Project2013 界面目录清单
- frame,iframe,frameset用法和区别
- Codeforces Gym 100650D Queens, Knights and Pawns 暴力
- scanf详解
- POJ1703 简单的种类并查集
- 转:理解C++11的模板类型推导
- 白酒香型
- [HDU 1281] 棋盘游戏 最大匹配
- 2015 Multi-University Training Contest 9(区间dp)
- StringGrid右击选中表格(发消息给句柄模拟点击,右键点击也是MouseDown)
- ZKW费用流修正
- 织梦DedeCms Runphp 标签中调用其他变量的方法
- linux curl 命令
- 编程技巧 - 3