题目描述:

给出一系列男女配对意愿信息。求一个集合中的最大人数,满足这个集合中两两的人不能配对。

/*
二分图的最大独立集
因为没有给出具体的男生和女生,所以可以将数据扩大一倍,即n个男生,n个女生,
根据定理,最大独立集=总数-匹配数(本题应该除以2)
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 510
using namespace std;
int a[N][N],used[N],belong[N],n;
bool find(int i)
{
for(int j=;j<=n;j++)
if(a[i][j]&&!used[j])
{
used[j]=;
if(!belong[j]||find(belong[j]))
{
belong[j]=i;
return true;
}
}
return false;
}
void work()
{
for(int i=;i<=n;i++)
{
int x,m;scanf("%d: (%d)",&x,&m);x++;
for(int j=;j<=m;j++)
{
int y;scanf("%d",&y);y++;
a[x][y]=a[y][x]=;
}
}
int tot=;
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(find(i))tot++;
}
printf("%d\n",n-tot/);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(belong,,sizeof(belong));
work();
}
return ;
}

Girls and Boys(poj 1466)的更多相关文章

  1. Girls and Boys POJ - 1466 【(二分图最大独立集)】

    Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...

  2. POJ 1466 Girls and Boys

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

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

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

  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: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

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

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

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

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

  8. POJ 1466:Girls and Boys 二分图的最大点独立集

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

  9. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

随机推荐

  1. HDU1907 John

    Description Little John is playing very funny game with his younger brother. There is one big box fi ...

  2. nginx配置ssl双向验证 nginx https ssl证书配置

    1.安装nginx 参考<nginx安装>:http://www.ttlsa.com/nginx/nginx-install-on-linux/ 如果你想在单IP/服务器上配置多个http ...

  3. Spring学习5-Spring整合JDBC及其事务处理(注解方式)

    一.整合的步骤   1.步骤一:首先要获得DataSource连接池(推荐使用B方式): 要对数据库执行任何的JDBC操作,需要有一个Connection.在Spring中,Connection对象是 ...

  4. jquery------导入jquery.2.2.3.min.js

    问题: 导入jquery.2.2.3.min.js后MyEclipse会提示代码有错误 方法: 选中jquery.2.2.3.min.js->右键->选择“MyEclipse”中的“Exc ...

  5. P、NP、NPC、NP-Hard问题

    转自:http://www.matrix67.com/blog/archives/105 总结 P:能用多项式时间求解的问题NP:能用多项式时间验证的问题(但不知道能不能用多项式时间求解).存在不属于 ...

  6. phpcms 调取全站文章

    路径:phpcms/module/content/classes/content_tag.class.php 添加如下方法 /** * 列表页标签:主要返回的是主表中数据与附表中数据 * @param ...

  7. struts2基本配置

    struts.xml 放在src目录下 <?xml version="1.0" encoding="UTF-8"?> <struts> ...

  8. sparkR操作HDFS上面的CSV文件

    ./bin/sparkR --packages com.databricks:spark-csv_2.10:1.3.0 --master yarn hdfs://master:9000/tmp/dem ...

  9. 我用的/etc/vimrc

    " 映射非数字/字母键, 如:ctrl,shift, alt, home,end,功能键F1~F12, 要把这些键用尖括号括起来!如: map <F3> :NERDTree< ...

  10. Hadoop之 hdfs 系统

    一.NameNode维护着2张表: 1.文件系统的目录结构,以及元数据信息 2.文件与数据块列表的对应关系 存放在fsimage中,在运行的时候加载到内存中的. 操作日志写到edits中   二.Da ...