UVALive 6851 The Programmers(二分图多重匹配)
来源:互联网 发布:java开发工程师工资 编辑:程序博客网 时间:2024/06/06 02:50
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=79617
题意:每组case给你P, S, C, m,代表有P个人,S个赛区,每个赛区最多能容纳C个人,接下来m行输入代表 x y 代表 第x个人只能去 赛区 y,
问最多有多少人可以参加比赛。
题解:直接套模板。或者跑最大流,建图比较简单。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <string>#include <map>#include <cstdlib>#include <cmath>#include <vector>#include <set>#include <queue>using namespace std;typedef long long ll;const int MAXN = 505;const int MAXM = 25;int uN,vN;int g[MAXN][MAXM];int linker[MAXM][MAXN];bool used[MAXM];int num[MAXM];bool dfs(int u) { for(int v = 0; v < vN; v++) if(g[u][v] && !used[v]) { used[v] = true; if(linker[v][0] < num[v]) { linker[v][++linker[v][0]] = u; return true; } for(int i = 1; i <= num[0]; i++) if(dfs(linker[v][i])) { linker[v][i] = u; return true; } } return false;}int hungary() { int res = 0; for(int i = 0; i < vN; i++) linker[i][0] = 0; for(int u = 0; u < uN; u++) { memset(used,false,sizeof(used)); if(dfs(u))res++; } return res;}int main() {#ifdef ONLINE_JUDGE#else freopen("test.in", "r", stdin);#endif int T; scanf("%d",&T); while(T--) { int C,m; scanf("%d%d%d%d",&uN,&vN,&C,&m); for(int i=0; i<vN; i++) { num[i]=C; } memset(g,0,sizeof(g)); for(int i=0; i<m; i++) { int u,v; scanf("%d%d",&u,&v); u--; v--; g[u][v]=1; } printf("%d\n",hungary()); } return 0;}
0 0
- UVALive 6851 The Programmers(二分图多重匹配)
- UVALive 6851The Programmers(最大流)
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- UVALive 5033 I'm Telling the Truth 二分图匹配
- 二分图多重匹配(HDU 2255)
- hihocoder1393(二分图多重匹配)
- UVAlive 6525 二分图匹配
- 二分图多重匹配问题
- 二分图的多重匹配
- 二分图多重匹配--poj2289
- 二分图多重匹配--poj2584
- 二分图的多重匹配
- Objective-C入门20:Block
- Android 蓝牙开发(一)Android系统的蓝牙模块简介
- EXCEL编程从0开始
- 字符串笔试题
- 第十四章 Vim之替换
- UVALive 6851 The Programmers(二分图多重匹配)
- sprintf_s使用时候报访问地址冲突
- Unsafe初涉
- 查看/修改Linux时区和时间
- matlab的xml操作
- eclipse luna安装ivy和ivyde插件方法
- 数据结构--图
- 配置TOMCAT远程Debug模式
- 关于Eclipse中“ctrl+鼠标左击类”快捷键不能查看该类API源代码的解决方法