Description
In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.

Input

The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description: 

the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:() The student_identifier is an integer number between and n- (n <= ), for n subjects.

Output

For each given data set, the program should write to standard output a line containing the result.

Sample Input

: ()
: ()
: ()
: ()
: ()
: ()
: () : ()
: ()
: ()

Sample Output


Source

 

题目大意:有n个学生,每个学生都和一些人又关系,现在要你找出最大的人数,使得这些人之间没关系

解题思路:裸的最大独立集,最大独立集=点数-最大匹配数
这里注意因为是两两匹配,所以求出的匹配值要除上个2

优化了几下,时间不断减少

 
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 506
int n;
int match[N];
int vis[N];
int mp[N][N];
bool dfs(int x){
for(int i=;i<n;i++){
if(!vis[i] && mp[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
void solve(){
int ans=;
memset(match,-,sizeof(match)); for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
}
printf("%d\n",n-ans/);
}
int main()
{ while(scanf("%d",&n)==){
memset(mp,,sizeof(mp));
char s[];
for(int i=;i<n;i++){
scanf("%s",s);
scanf("%s",s);
int num=;
for(int j=;j<strlen(s);j++){
if(s[j]>='' && s[j]<=''){
num=num*+s[j]-'';
}
}
//printf("---%d\n",num);
int x;
for(int j=;j<num;j++){
scanf("%d",&x);
mp[i][x]=mp[x][i]=;
}
}
solve();
}
return ;
}

poj 1466 Girls and Boys(二分匹配之最大独立集)的更多相关文章

  1. POJ 1466 大学谈恋爱 二分匹配变形 最大独立集

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11694   Accepted: 5230 D ...

  2. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  3. POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题

    有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...

  4. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  5. poj 1466 Girls and Boys 二分图的最大匹配

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  6. hduoj-----(1068)Girls and Boys(二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  9. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  10. poj 1466 Girls and Boys (最大独立集)

    链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...

随机推荐

  1. AngularJs学习笔记6——四大特性之依赖注入

    压缩工具:YUI-compressor 为了优化网页功能,对一些脚本文件进行压缩,比如:删除所有的注释和空格等,简化形参.但是AngularJs模块中可以声明多种组件,如控制器.指令.过滤器.服务等. ...

  2. JAVA基础1

    阶段0:拟出一个计划 阶段1:要制作什么? 阶段2:如何构建? 阶段3:开始创建 阶段4:校订 阶段5:计划的回报   一.程序运行时,数据保存位置 1.寄存器.这是最快的保存区域,因为它位于和其他所 ...

  3. Face recognition using Histograms of Oriented Gradients

    Face recognition using Histograms of Oriented Gradients 这篇论文的主要内容是将Hog算子应用到人脸识别上. 转载请注明:http://blog. ...

  4. [React] React Router: hashHistory vs browserHistory

    In this lesson we'll look at hashHistory which uses a hash hack to track our route changes vs browse ...

  5. HID class request.

    1.get report. 2.set report report request. Get report范例: 下面这张图是Host跟Device来要设备描述符. USB主机向设备控制器请求数据时, ...

  6. C# - CSV(Comma-Separated Values)文件读取.

    using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...

  7. .net framework 注册到IIS上

    首先要安装好所需的IIS版本和.net framework 各版本,注册方式如下: 1.1:C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_re ...

  8. Java学习笔记(2):jdk的配置

    配置Java的开发环境 先说明一下,我的jdk文件目录是:D:\language\java\java soft\jdk1.6 JDK的安装与配置 解压“开发软件”中的jdk1.6.rar(解压版)到D ...

  9. 机器学习理论与实战(十)K均值聚类和二分K均值聚类

    接下来就要说下无监督机器学习方法,所谓无监督机器学习前面也说过,就是没有标签的情况,对样本数据进行聚类分析.关联性分析等.主要包括K均值聚类(K-means clustering)和关联分析,这两大类 ...

  10. Linux 编译安装httpsqs

    wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz tar zxvf libevent-2.0.12-stab ...