poj 1274 基础二分最大匹配
#include<stdio.h>
#include<string.h>
#define N 300
#define inf 0x3fffffff
int mark[N],link[N],n,m;
int map[N][N];
int find(int u) {
int i;
for(i=1;i<=m;i++) {
if(!mark[i]&&map[u][i]) {
mark[i]=1;
if(link[i]==-1||find(link[i])) {
link[i]=u;
return 1;
}
}
}
return 0;
}
int main() {
int i,k,s,t;
while(scanf("%d%d",&n,&m)!=EOF) {
memset(map,0,sizeof(map));
memset(link,-1,sizeof(link));
for(i=1;i<=n;i++) {
scanf("%d",&s);
while(s--) {
scanf("%d",&t);
map[i][t]=1;
}
}
k=0;
for(i=1;i<=n;i++) {
memset(mark,0,sizeof(mark));
k+=find(i);
}
printf("%d\n",k);
}
return 0;
}
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 3041 Asteroids(模板——二分最大匹配(BFS增广))
题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...
- hdu2063 匈牙利算法 二分最大匹配模版题
过山车 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class na ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
- hdu 2444 交叉染色判断二分图+二分最大匹配
/*1A 31ms*/ #include<stdio.h> #include<string.h> #define N 300 int n; struct node { int ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
随机推荐
- oc27--synthesize,省略getset实现
// // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject { @public int _a ...
- linux端口号与PID的互相查询
最近用linux在玩Tomcat,启动的时候总是会报错(8080/8009/8005) 于是整理了一下网上零乱的查看PID和端口的命令,以备记录. 1.由端口号查询PID号 首先myeclipse报错 ...
- python统计ES存储空间占用的代码
import os from os.path import join, getsize def get_dir_size(dir, suffix_filter=None): size = 0L if ...
- B2568 比特集合 树状数组
啊啊啊,跳题坑死人.抽了一道国集的题,自己瞎编了一个算法,好像过不了而半途而废.转去看题解,发现用二维树状数组维护一下,偏移量我倒是想对了,但是维护的东西和我的完全不一样.还是有很大差距啊... 题解 ...
- 数据结构C++,线性表的实现
#include <iostream>#include <sstream>#include <fstream>#include <cmath>#incl ...
- 网上订餐系统的SQL SERVER 2005数据库连接
- E20170813-ts
explicitly adv. 明白地,明确地;
- day-05 python函数
# #-*- coding:utf-8 -*-# 1:编写一个名为 make_shirt()的函数,它接受一个尺码以及要印到 T 恤上的字样.这个函数应打印一个句子,概要地说明 T 恤的尺码和字样.d ...
- C - Anton and Danik
Problem description Anton likes to play chess, and so does his friend Danik. Once they have played n ...
- VR: AR和VR演进哲学
Facebook 20亿美元(4亿美元+16亿美元股票换购方式)收购虚拟现实厂商Oculus 引爆AR产业,索尼不温不火逐步演进的头盔项目也该加速了.最近Oculus rift发布了商业版本:Ocul ...