hdu1068 Girls and Boys
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1068
二分图的最大独立集数=节点数(n)— 最大匹配数(m)
另外需要注意的是:
本题求出的最大匹配数是实际的两倍需要m/2
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
const int N=;
int a[N][N];
int match[N];
int use[N];
int n;
int dfs(int u)
{
for(int i=;i<n;i++)
{
if(a[u][i] && !use[i])
{
use[i]=;
if(match[i]==- || dfs(match[i]))
{
match[i]=u;
return ;
}
}
}
return ;
}
int bipartite()
{
int res=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++)
{
memset(use,,sizeof(use));
if(dfs(i))
res++;
}
return res;
}
int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
int q,p,m;
memset(a,,sizeof(a));
for(int i=;i<n;i++)
{
scanf("%d: (%d) ",&q,&m);
for(int j=;j<m;j++)
{
scanf("%d",&p);
a[q][p]=;
}
}
int x=n-bipartite()/;
printf("%d\n",x);
}
return ;
}
hdu1068 Girls and Boys的更多相关文章
- hdu1068 Girls and Boys 二分匹配
题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...
- hdu1068 Girls and Boys 匈牙利算法(邻接表)
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...
- hdu1068 Girls and Boys 基础匈牙利
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> ...
- hdu1068 Girls and Boys --- 最大独立集
有一个集合男和一个集合女,给出两集合间一些一一相应关系.问该两集合中的最大独立集的点数. 最大独立集=顶点总数-最大匹配数 此题中.若(a,b)有关.则(b,a)有关.每个关系算了两次,相当于二分图的 ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
随机推荐
- oracle11.0.2 64位版本 Toad连接
今天重装了系统 oracle oracle客户端 之前连不上toad 今天总结 客户端路径:E:\app\ruonanxiao-pc\product\11.2.0\client_1 服务端路径:E: ...
- 大仙说道之Android studio实现Service AIDL
今天要开发过程中要用到AIDL的调用,之前用的eclipse有大量教程,用起来很方便,现在刚换了Android studio,不可否认studio真的很强大,只是很多功能还需要摸索. AIDL(And ...
- Ping N个IP测试网络连通性
#-----------------------Smokeping移动节点-------------------##! /bin/bashecho "------------- Statin ...
- Mysql数据库常用的命令 数据备份 恢复 远程
远程数据库 格式: mysql -h主机地址 -u用户名 -p用户密码数据库 mysql -h 42.51.150.68 -u yang -p discuz mysql设置密码 mysql>us ...
- python2.7之乱码问题(直接从我的csdn上复制粘贴过来的。。。)
学习python一段时间了,一直没有写过博客.就从今天开始吧! python 3之后当然不存在乱码问题了.python 2的乱码问题有时就有点头疼了.(代码均为在windows下测试) 示例:保存为t ...
- Python GUI编程实践
看完了<python编程实践>对Python的基本语法有了一定的了解,加上认识到python在图形用户界面和数据库支持方面快捷,遂决定动手实践一番. 因为是刚接触Python,对于基本的数 ...
- C/C++运算符优先级
运算符优先级从高至低 优先级 操作符 描述 例子 结合性 1 ()[]->.::++-- 调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作 ...
- Unity 优化
1. 尽量避免每帧处理比如: function Update() { DoSomeThing(); } 可改为每5帧处理一次: function Update() { == ) { DoSomeThi ...
- inputstream和outputstream读写数据模板代码
//读写数据模板代码 byte buffer[] = new byte[1024]; int len=0; while((len=in.read(buffer))>0){ out.write(b ...
- 7zip 命令行
转自 http://www.cnblogs.com/langlang/archive/2010/12/01/1893866.html 7z.exe 是 7-Zip 的命令行版本.7z.exe 使用 7 ...