POJ 1274
#include<iostream>
#include<stdio.h>
#include <string.h>
#include <vector>
#define MAXN 251
#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)
#define _clr(x) memset(x,0xff,sizeof(int)*MAXN) using namespace std; int hungary(int m,int n,int mat[][MAXN],int* match1,int* match2);
int _m[MAXN][MAXN];
int match1[MAXN];
int match2[MAXN];
int main()
{
//freopen("acm.acm","r",stdin);
int M;
int N;
int n;
int i;
int j;
// bool M_N;
int s;
while(cin>>M>>N)
{
// if(M <= N)
// M_N = true;
for(i = ; i < MAXN; ++i)
{
memset(_m[i],,sizeof(int)*MAXN);
}
for(i = ; i < M; ++ i)
{
cin>>s;
for(j = ; j < s; ++ j)
{
cin>>n;
// if(M_N)
// {
_m[i][n-] = ;
// }
// else
// {
// _m[n-1][i] = 1;
// }
}
}
// if(M_N)
cout<<hungary(M,N,_m,match1,match2)<<endl;
// else
// cout<<hungary(N,M,_m,match1,match2)<<endl;
}
} int hungary(int m,int n,int mat[][MAXN],int * match1,int* match2){
int s[MAXN],t[MAXN],p,q,ret=,i,j,k;
for (_clr(match1),_clr(match2),i=;i<m;ret+=(match1[i++]>=))
for (_clr(t),s[p=q=]=i;p<=q&&match1[i]<;p++)
for (k=s[p],j=;j<n&&match1[i]<;j++)
if (mat[k][j]&&t[j]<){
s[++q]=match2[j],t[j]=k;
if (s[q]<)
for (p=j;p>=;j=p)
match2[j]=k=t[j],p=match1[k],match1[k]=j;
}
return ret;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1274的更多相关文章
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)
Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- [题解]poj 1274 The Perfect Stall(网络流)
二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...
- [题解]poj 1274 The Prefect Stall
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...
- Poj(1274),二分图匹配
题目链接:http://poj.org/problem?id=1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Tota ...
- [POJ] 1274 The Perfect Stall(二分图最大匹配)
题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...
- poj 1274 The Perfect Stal - 网络流
二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...
- poj 1274 The Prefect Stall - 二分匹配
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...
随机推荐
- Lambda前世今生
1.学习资料 匿名函数 C#编程指南http://msdn.microsoft.com/zh-cn/library/bb882516.aspx Lambda表达式 C#编程指南http://msdn. ...
- hdu 1973 Prime Path
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Description The ministers of the cabi ...
- iOS学习之UINavigationController
一.UINavigationController 1.UINavigationController:导航控制器,是iOS中最常用的多视图控制器之一,用它来管理多个视图控制器.可以称为是管理控 ...
- ExtJS FormPanel不执行校验
经检查问题原因在于使用了 validator 属性. 使用validator属性,必须添加返回值.不添加返回值,就会出现FormPanel不执行校验的问题.
- [转]network-manager与interfaces冲突
[转]network-manager与interfaces冲突 http://blog.sina.com.cn/s/blog_48a45b9501010681.html 网络配置的两种方式 ...
- with check option
通过有with check option选项的视图操作基表(只是面对单表,对连接多表的视图正在寻找答案),有以下结论:首先视图只操作它可以查询出来的数据,对于它查询不出的数据,即使基表有,也不可以通过 ...
- Python实现LR(逻辑回归)
Python实现LR(逻辑回归) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=>end o ...
- Function-两个日期大小比较
function checkDate(from,to){ if (from == "" || to == "") return 2; var rValue = ...
- 5方与5W
方案:方位(角色).方向.方针.方式.方法 解答5W2H 轻重.缓急.深浅
- 断点续传 (HTTP) 归纳
由于最近项目中要上传较大的文件,基于公司原有的底层框架的局限性,对于大文件的传输都束手无策,基于文件传输的安全性,考虑用断点续传(HTTP)以及FTP上传两种方式实现下面归纳下HTTP续传和FTP上传 ...