poj 1274The Perfect Stall 二分匹配模板水题
来源:互联网 发布:暗黑2优化高清补丁 编辑:程序博客网 时间:2024/05/24 04:30
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 210;
int match[maxn];
int line[maxn][maxn];
int vis[maxn];
int N , M;
int find(int start)
{
for(int i = 1;i <= M;i++)
{
if(!vis[i]&&line[start][i])
{
vis[i] = 1;
if(match[i] == -1 || find(match[i]))
{
match[i] = start;
return 1;
}
}
}
return 0;
}
void Match()
{
memset(match, -1 , sizeof(match));
int ans=0;
for(int i = 1;i <= N;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
ans++;
}
printf("%d\n",ans);
}
int main()
{
while(scanf("%d%d" , &N , &M)!=EOF)
{
memset(line,0,sizeof(line));
for(int i = 1;i <= N;i++)
{
int num;
scanf("%d" , &num);
while(num--)
{
int v;
scanf("%d", &v);
line[i][v]=1;
}
}
Match();
}
return 0;
}
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 210;
int match[maxn];
int line[maxn][maxn];
int vis[maxn];
int N , M;
int find(int start)
{
for(int i = 1;i <= M;i++)
{
if(!vis[i]&&line[start][i])
{
vis[i] = 1;
if(match[i] == -1 || find(match[i]))
{
match[i] = start;
return 1;
}
}
}
return 0;
}
void Match()
{
memset(match, -1 , sizeof(match));
int ans=0;
for(int i = 1;i <= N;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
ans++;
}
printf("%d\n",ans);
}
int main()
{
while(scanf("%d%d" , &N , &M)!=EOF)
{
memset(line,0,sizeof(line));
for(int i = 1;i <= N;i++)
{
int num;
scanf("%d" , &num);
while(num--)
{
int v;
scanf("%d", &v);
line[i][v]=1;
}
}
Match();
}
return 0;
}
0 0
- poj 1274The Perfect Stall 二分匹配模板水题
- POJ-1274The Perfect Stall,二分匹配裸模板题
- POJ 1274 The Perfect Stall 二分匹配模板
- 【POJ】1274 The Perfect Stall 二分匹配
- Poj 1274 The Perfect Stall【二分匹配】
- POJ 1274 The Perfect Stall 水二分匹配
- 二分图匹配(简单题)POJ 1274 The Perfect Stall
- poj 1274 The Perfect Stall 【二分匹配裸题】【练模板】
- POJ-1274-The Perfect Stall【二分图最大匹配】【模板题】
- POJ-1274 The Perfect Stall (二分图最大匹配模板题)
- POJ 1274 The Perfect Stall(最大二分匹配)
- POJ 1274 The Perfect Stall 二分图最大匹配
- 二分图最大基数匹配 POJ 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分图最大匹配)
- 【二分图+最大匹配】北大 poj 1274 The Perfect Stall
- poj 匈牙利二分匹配 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分匹配)
- POJ 1274 The Perfect Stall 【二分图匹配】
- google pay billing 支付嵌入中需要注意的问题
- 自定义iOS上双击Home键图切换
- java 操作Excel简单示例
- Android项目R文件丢失问题—自己总结
- UVA - 202 Repeating Decimals
- poj 1274The Perfect Stall 二分匹配模板水题
- 水平触发和边缘触发的区别
- 复杂的桶排序
- 安装loadrunner
- 深入理解Java多态性
- maven初步
- jQuery.data() 的实现方式
- 13、自定义控件之开关
- java(24) - 内部类详解