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 ...
随机推荐
- oracle-审计导数
1.因审计需求,需要将MySQL.Oracle数据库中需要的表数据导入到SqlSERVER进行审计. 2.之前的方法: A. oracle组将表dump下来,进行压缩,传送到oracle导数服务器 ...
- 【6.24-AppCan移动开发大会倒计时】科大讯飞来了!
6.24 AppCan移动开发者大会进入倒计时,报名通道即将关闭! 50多家移动圈服务商将出席此次大会,讯飞开放平台也将作为参展商,为参会者带去前沿的语音技术.参会者可现场体验最新连续语音识别技术,识 ...
- eclipse创建android项目失败的问题 [ android support library ]
有根筋搭错了,想起来android应用开发???? 放下两年的手机应用开发,昨天有更新了android SDK, 重新搭建开发环境. 这两年android 变化真TM的大............... ...
- golang:slice陷阱
slice陷阱,slice底层指向某个array,在赋值后容易导致array长期被引用而无法释放
- [译]rabbitmq 2.5 Where’s my message? Durability and you
我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家. There’s a dirty secret about creating queues and exchanges in ...
- mysql TRUNCATE
保留小数点 select truncate(field1,2) from table1 field3 字段类型为decimal(20,3)
- 归并排序 & 计数排序 & 基数排序 & 冒泡排序 & 选择排序 ----> 内部排序性能比较
2.3 归并排序 接口定义: int merge(void* data, int esize, int lpos, int dpos, int rpos, int (*compare)(const v ...
- verilog 学习笔记
1.在寄存器中: -1=1111 -2=1110 -3=1101 2.{1,0}=64‘H00000001_00000000;//默认是32位的位数-拼接: 3.defparam P1.Depth=1 ...
- VC++编程之对话框贴图
基于对话框的程序写好后,为对话框贴上个图片让界面更加美观(我承认做界面,MFC显得力不从心,不如QT). 其实很简单,我们以位图为例,选好我们需要的位图资源(bmp),假若自己的图片不是位图资源,可以 ...
- Java类初始化顺序问题
main -> (静态变量.静态代码块) ->main函数体 -> (类变量.初始化块.实例化引用的类) -> 构造函数 初始化块与实例化引用的类 的调用顺序 按程序的编写上下 ...